在matlab中混合使用plotyy和semilogy时,yticks无法正确显示

时间:2012-06-04 05:41:54

标签: matlab plot

我正在使用plotyy绘制同一图中不同轴的两条曲线。第一条曲线的范围为10 ^ -4到10 ^ -1,第二条曲线的范围为0到10.如果我按以下方式绘制,

[AX,H1,H2] = plotyy(x,y1,x,y2,'semilogy','semilogy');

他们都将绘制为半月形并且在y中具有正确的比例。但是我不希望以log10比例显示y2,所以我改变了

[AX,H1,H2] = plotyy(x,y1,x,y2,'semilogy','plot');

然而,然后在左右y轴上,勾选仅显示最小和最大范围,所有细节之间消失。为什么?

2 个答案:

答案 0 :(得分:2)

你可以试试这个:

[AX, H1, H2] = plotyy(x, y1, x, y2, 'semilogy', 'plot');

% set yticks for the left axis 
set(AX(1), 'ytick', yourDesiredYticks1)
set(AX(1), 'box', 'off') % to remove corresponding yticks on the right side of the plot

% set yticks for the right axis
set(AX(2), 'ytick', yourDesiredYticks2)
set(AX(2), 'box', 'off')

答案 1 :(得分:1)

试试这个:

%# create some data resembling what you described
x = 1:100;
y1 = rand(size(x))*1e-1 + 1e-4;
y2 = rand(size(x))*10;

%# plot
hAx = plotyy(x,y1, x,y2, 'semilogy', 'semilogy');
set(hAx(2), 'YScale','linear')

screenshot