How to plot left and right y-axis that belong to the same data points
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
pfb
on 22 Apr 2015
Edited: pfb
on 22 Apr 2015
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 Comments
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!