plotyy with sync yaxis tics on both sides

3 vues (au cours des 30 derniers jours)
Matthias Pospiech
Matthias Pospiech le 8 Fév 2012
Modifié(e) : Cedric le 6 Oct 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.

Réponse acceptée

Kevin Holst
Kevin Holst le 8 Fév 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 commentaires
Matthias Pospiech
Matthias Pospiech le 9 Fév 2012
Sure, I know that. But it does not help me at all, since I need the ticks to be automatically applied. They do not need to be at the same positions, for example it could be 4 ticks on the right and 5 on the left side. But then the ticks for y1 should only appear on the left and for y2 only on the right side. This is my question - not how to manualy configure the tick positions.
Kevin Holst
Kevin Holst le 9 Fév 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by