How to plot left and right y-axis that belong to the same data points
3 次查看(过去 30 天)
显示 更早的评论
Dear All,
I am trying to create a plot that displays 2 y-axis (one on the left and one on the right). I have tried using the plotyy function, however the results are not the ones I am looking for.
I am uploading a picture that shows what I want to get:
The left y-axis is a difference in degrees while the right y-axis is an error in % for each point in the plot. For example, the point corresponding to the value of 40 on x-axis, has -0.01 degrees difference and an equivalent of 0.0349% error.
I hope I have expressed the issue clearly and I hope there is a solution :)
Thank you all,
Radu
0 个评论
采纳的回答
pfb
2015-4-22
编辑:pfb
2015-4-22
So if I get it right, you want to represent the same data using different units. I can see why plotyy is not the right tool.
You could use a second transparent set of axes.
If h is the handle to your axes, (the one for the left scale),
p = get(h,'position'); % gets the axes position
a = axis(h); % gets the axis limits
h2 = axes('position',p,'color','none'); % draws another axes with transparent background over h.
axis(a); % sets the same limits as in h
hold on;
then you need to get rid of the duplicate stuff. It's probably best to keep only the righ y axis
box off
set(h2,'Xtick',[],'YAxisLocation','right');
Next you need to set the same ticks on the left and right axis
set(h2,'Ytick',get(h,'Ytick'));
Finally, you take care of the new unit
set(h2,'YtickLabel',ytl);
where ytl is a vector containing the appropriate values in the other unit of measure. This should work
set(h2,'YtickLabel',abs(get(h,'YTickLabel'))/0.01*0.0349);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!