Effacer les filtres
Effacer les filtres

How to get different scaling with the same range on the same axis?

3 vues (au cours des 30 derniers jours)
Souhir Masmoudi
Souhir Masmoudi le 28 Avr 2016
Hi everybody,
I would like to have two different scales on the same y-axis in a contourf plot (I have the same problem with plotyy)
I want the scale to be 1 from 3 to 9 (i.e. 3,4,5,…,9). And then I want the scale to be 10 from 20 to 100 (i.e. 10,20,30,…100).
When I plot the data, I get this graduation 0 10 20 … 100 on the y-axis. The plot is condensed from 0 to 10 and homogeneous for the rest of the axis.
I would like these two scales have the same range. i.e. an y-axis with this graduation 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100. so the plot is homogeneous everywhere.
Any help would be greatly appreciated.
Thank you.

Réponses (2)

Jon le 28 Avr 2016
I don't know of any commands that accomplish what you want, but you could rescale your y-axis, plot normally, then set your tick labels appropriately. You want the distance on your plot from 3 to 4 to be the same as 10-20, so rescale your y-data so this is the case. If your y-vales are Y, something like this:
idcs = find(Y>10) % saving these for later
Y(Y>=3 && Y<=10) = Y(Y>=3 && Y<=10)*10; % rescale on [3 10]
Now you must adjust your y-values above 10 to account for the extra space added to [3 10]. We added (10-3)*10 = 70 values on the range [3 10], so we must add 70 values to y>10
Y(idcs) = Y(idcs) + (10-3)*10;
Now when you plot with Y, you should see the scaling you want. The last thing is to fix the ticklabels.
ytix = 30:10:max(Y);
ytixlabel = [3:10 20:10:max(Y)];
I haven't tested this, so it might be a little off, but it's one way you could try to solve your problem.

Souhir Masmoudi
Souhir Masmoudi le 4 Mai 2016
Hi Jon,
Thank you very much. This is what I needed!!
I tested it. I just corrected the third line of the code and it works well. I replaced this
Y(idcs) = Y(idcs) + (10-3)*10;
Y(idcs) = Y(idcs) + Y(10-3);
Thanks again!!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by