plotyy with sync yaxis tics on both sides

조회 수: 10 (최근 30일)
Matthias Pospiech
Matthias Pospiech 2012년 2월 8일
편집: Cedric 2013년 10월 6일
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.

채택된 답변

Kevin Holst
Kevin Holst 2012년 2월 8일
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
Matthias Pospiech
Matthias Pospiech 2012년 2월 9일
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 2012년 2월 9일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by