XY绘图与两个y轴Matlab

时间:2015-02-21 16:21:57

标签: matlab plot

我正在尝试用两个y轴创建一个xy图。我有三组速度数据。我试图创建一个图表,其中一个y轴显示速度的变化,另一个y轴显示距离。请参阅附图。但是,每组数据都是在x轴上看到的一个位置。我该怎么做?

Desired xy plot. You can see there are three curved lined representing the velocity data recorded. The y axis on the left shows the variation of velocity. The y axis on the left shows distance and the x axis shows the position where the data was recorded, ie 1,2 or 3.

问候,杰尔

2 个答案:

答案 0 :(得分:0)

这是你想要的吗?

x1 = 1:10;             %// example x1 data
y1 = x1.^2;            %// example y1 data
x2 = 5:12;             %// example x2 data
y2 = sqrt(x2);         %// example y2 data
plotyy(x1,y1,x2,y2)    %// plot y1 as a function of x1, and y2 as a function of x2

检查plotyy documentation选项。

enter image description here

答案 1 :(得分:0)

您可以对速度数据进行标准化,并将其绘制在不同的x位置。但是,一旦速度变化太大,预计曲线会重叠。

% define the x locations:  
xloc = [1 2 3];

% set up dummy velocity data:
y = linspace(0,1,101);
phi = linspace(0,pi,101);

vel(1,:) = sin(phi).*0.1;
vel(2,:) = sin(phi).*0.2;
vel(3,:) = sin(phi).*0.3;

% normalize with the global max velocity
vel_nondim = vel ./ max(max(vel));

% plot, using the defined x-locations
hold on
plot(xloc(1) + vel_nondim(1,:), y, 'g')
plot(xloc(2) + vel_nondim(2,:), y, 'b')
plot(xloc(3) + vel_nondim(3,:), y, 'r')

% x limits and ticks
xlim([0 4])
set(gca,'XTick',[1 2 3])

你最终会得到这个情节:

xlocplot