同一圖中具有不同的y軸的另一曲線圖我有三個數據集以及它們的誤差的向量。我想在同一個圖上繪製它們,其中數據集位於相同的y軸上(左側),錯誤位於同一個圖上,但是具有不同的軸(右側)。劇情幾種圖表和一個y軸和上在Matlab
功能plotyy允許這樣做對各軸1個情節,我該怎麼做了好地塊?
同一圖中具有不同的y軸的另一曲線圖我有三個數據集以及它們的誤差的向量。我想在同一個圖上繪製它們,其中數據集位於相同的y軸上(左側),錯誤位於同一個圖上,但是具有不同的軸(右側)。劇情幾種圖表和一個y軸和上在Matlab
功能plotyy允許這樣做對各軸1個情節,我該怎麼做了好地塊?
另外,也可以使用與plotyy()
y值的多個行。
繼從MATLAB的幫助的例子:
x = 0:0.01:20;
y1 = [200*exp(-0.05*x).*sin(x);
300*exp(-0.04*x).*sin(x)];
y2 = [0.8*exp(-0.5*x).*sin(10*x);
0.6*exp(-0.4*x).*sin(5*x)];
[AX,H1,H2] = plotyy(x,y1,x,y2);
set(get(AX(1),'Ylabel'),'String','Slow Decay')
set(get(AX(2),'Ylabel'),'String','Fast Decay')
xlabel('Time (\musec)')
title('Multiple Decay Rates')
set(H1,'LineStyle','--')
set(H2,'LineStyle',':')
產生如下圖
我想你應該手動創建新axes
:
figure(1); clf, hold on
x1 = 0:0.1:5*pi;
y1 = sin(x1)./x1;
x2 = 0:0.1:5*pi;
y2 = x2.^(0.2);
x3 = 0:0.1:5*pi;
y3 = cos(x3);
plot(x1,y1, 'b', 'linewidth', 2)
plot(x2,y2, 'g', 'linewidth', 2)
plot(x3,y3, 'k', 'linewidth', 2)
ax1 = gca;
ax2 = axes('Position', get(ax1,'Position'),...
'YAxisLocation','right',...
'Color' , 'none',...
'YColor', 'r');
linkaxes([ax1 ax2], 'x')
x4 = x3;
y4 = 0.025*randn(size(y3));
line(x4, y4, 'color', 'r', 'parent', ax2)
輸出:
這裏的東西,你可以嘗試:
% Example data
x = [1 2 3];
yd1 = [1 1 1];
yd2 = [2 2 2];
yd3 = [3 3 3];
ye1 = [0.1 0.2 0.3];
ye2 = [0.2 0.3 0.4];
ye3 = [0.3 0.4 0.5];
% Create two axes
ax1 = axes();
ax2 = axes();
% Plot your data
line(x, yd1, 'Parent', ax1, 'Color', 'b');
line(x, yd2, 'Parent', ax1, 'Color', 'b');
line(x, yd3, 'Parent', ax1, 'Color', 'b');
line(x, ye1, 'Parent', ax2, 'Color', 'r');
line(x, ye2, 'Parent', ax2, 'Color', 'r');
line(x, ye3, 'Parent', ax2, 'Color', 'r');
% Modify axes properties
set(ax1, 'ylim', [-10 4]);
set(ax2, 'Color', 'none', 'YAxisLocation', 'right', 'XTick', []);
我已經使用line
,而不是plot
,因爲plot
給了我一些 問題與y軸的刻度。更多信息here。
下面是使用滑鐵盧的代碼由@natan
x = 0:0.01:20;
y1 = [200*exp(-0.05*x).*sin(x);300*exp(-0.04*x).*sin(x)];
y2 = [0.8*exp(-0.5*x).*sin(10*x);0.6*exp(-0.4*x).*sin(5*x)];
f=GXFigure();
ax=subplot(f,1,1,1);
p1=line(ax, x, y1(1,:), 'LineColor', 'SEAGREEN');
p2=line(p1, [], y1(2,:), 'LineColor', 'TOMATO');
ax.getObject().getView().setXLabel(sprintf('Time Slow Decay %cs', char(181)));
layer1=kcl.waterloo.graphics.GJGraph.createInstance();
ax.getObject().getView().add(layer1);
p3=line(wwrap(layer1), x, y2(1,:), 'LineColor', 'CORNFLOWERBLUE');
p4=line(p3, x, y2(2,:), 'LineColor', 'CRIMSON');
layer1.setXLabel(sprintf('Time Fast Decay %cs', char(181)));
ax.getObject().setTitleText('Multiple Decay Rates');
建議了產生:
對於其他例子見here
這是畫出兩個Y軸,使您可以使用相同的標記和範圍制定者在正常繪圖最簡單的方法:ylim
,ylabel
等。
從docs。
yyaxis left;
plot(x, y_left);
ylim([0, 100]); % sets the limits for the left y axis
ylabel('left axis');
yyaxis right;
plot(x, y_right);
ylim([0, 100]); % sets the limits for the right y axis
ylabel('right axis');
+1:best one yet –