plotyy with sync yaxis tics on both sides
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthias Pospiech
am 8 Feb. 2012
Bearbeitet: Cedric
am 6 Okt. 2013
Matlab does provide plotyy for plotting two graphs with different yaxis, but does not sync the tics. Also matlab provides no possibility to switch of the tics on the opposite side. so far my knowledge.
Now I want to plot two lines whith completely unrelated y-data. Currently the tics of left and right axis are not in sync and the plot therefore looks messed up.
So I need a solution to sync the tics on he y-axis on both sides. ( A problem also dicusses with the same topic here.)
My actual plot function is this one
[AX,H1,H2] = plotyy(xaxis, ydata1, xaxis, ydata2);
A solution found on the thread linked above is the following one, but I do not see how to integrate it with my plot function (the plot is empy after I execute this code)
% dummy axes for the box and background color
ax0 = axes;
set (ax0, 'Box', 'on', 'Color', 'white', 'XTick', [], 'YTick', []);
% first axes for left y-axis
ax1 = axes ('Position', get (ax0, 'Position'));
set (ax1, 'Box', 'off', 'Color', 'none', 'YAxisLocation', 'left');
% second axes for right y-axis assuming common x-axis controlled by ax1
ax2 = axes ('Position', get (ax0, 'Position'));
set (ax2, 'Box', 'off', 'Color', 'none', 'XTick', [], 'YAxisLocation', 'right');
Any hint welcome.
0 Kommentare
Akzeptierte Antwort
Kevin Holst
am 8 Feb. 2012
Matlab allows you to switch the ticks on both axes. plotyy is creating two overlapping axes on the figure. When you execute this command:
[AX,H1,H2] = plotyy(xaxis, ydata1, xaxis, ydata2);
AX returns a 2x1 double array with the two axis handles. If you want to adjust the ticks and tick labels for the right axis, the command would be:
set(AX(2),'YTick',<your array>)
set(AX(2),'YTickLabel',<your cell array>)
2 Kommentare
Kevin Holst
am 9 Feb. 2012
I apologize. Based on your original question it appeared that you did not, in fact, know that, and that it would help you. You have since clarified you question, so now I can suggest using addaxis from the file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/9016-addaxis
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Two y-axis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!