How to get different scaling with the same range on the same axis?
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Jon
2016-4-28
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);
set(gca,'ytick',ytix)
ytixlabel = [3:10 20:10:max(Y)];
set(gca,'yticklabel',ytixlabel)
I haven't tested this, so it might be a little off, but it's one way you could try to solve your problem.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!