plotyy with sync yaxis tics on both sides
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
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 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!