# plotyy with axis for each plot only on one side

조회 수: 10(최근 30일)
Matthias Pospiech 2012년 2월 11일
편집: Andrei Bobrov 2013년 10월 11일
The following code shows my problem. plotyy completely fails if the ticks are not at the same positions on both sides (which is rather the normal case...)
I require a plot with two y axis but the ticks only on one side. I was suggested to use addaxis, but I do not see how that helps me, since I do not want separated axis.
clf;
clc;
xaxis = 0:0.1:25;
y1 = linspace(12.1712,12.7679, length(xaxis));
y2 = linspace(0.3597,-28.7745, length(xaxis));
[AX,H1,H2] = plotyy(xaxis, y1, xaxis, y2);
% axis limits - x axis (min to max)
xlimits(1) = min(xaxis); xlimits(2) = max(xaxis);
set(AX, 'XLim', xlimits);
set(AX(2),'XTick',[]);
% y1 axis limits
ylimits(1) = min(ydata1); ylimits(2) = max(ydata1);
ylimits(2) = ylimits(2) + (ylimits(2)-ylimits(1))*0.05;
set(AX(1), 'YLim', ylimits);
% y2 axis limits
ylimits(1) = min(ydata2); ylimits(2) = max(ydata2);
ylimits(2) = ylimits(2) + (ylimits(2)-ylimits(1))*0.05;
set(AX(2), 'YLim', ylimits);
% y1 ticks
set(AX(1),'YTick',[12.0:0.1:12.8]);
% y2 ticks
set(AX(2),'YTick',[-25:5:0]);
print(gcf, ['-r' num2str(400)], ['test' '.png' ], ['-d' 'png']);
I would like to provide an example picture, but this forum does not allow to add images.
If this is not solvable with matlab, I will have to suggest the person which asked me if their data can be plotted with matlab to use something different.
##### 댓글 수: 1표시숨기기 없음
the cyclist 2012년 2월 11일

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

### 채택된 답변

the cyclist 2012년 2월 11일
The problem is that the tick marks of the left-hand axes (axis 1) are drawn on both the left and right edges of the plot. (Even when you use just the plot() function, the ticks marks appear on both the left- and right-hand side of the axis. )
Here is a work-around that might be acceptable.
figure
ax=plotyy(1:10,1:10,1:100,1:100);
set(ax(2),'YTick',[]) % Remove ticks of axis 2 (leaves right-hand ticks of axis 1)
set(ax(1),'Box','off') % Turn off box of axis 1, which removes its right-hand ticks
This code will remove the right-hand ticks of axis 1, but also right-hand and top edges of the box. I don't know of a better way.
However, you might also want to try this submission from the FEX: http://www.mathworks.com/matlabcentral/fileexchange/4936-plt which I understand has better control over some of these things. (I haven't used it myself.)
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
the cyclist 2012년 2월 14일
That command does have an effect. If you run my code, but leave out that command, you will see the ticks of the right-hand axis.
You might be able to get the effect you want by just using the line() command to manually put in the axis lines. I'm not sure.

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

### Community Treasure Hunt

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

Start Hunting!