XY Plot with two y-axes Matlab

I am trying to create an xy plot with two y-axes. I have three speed data sets. Im trying to create a graph with one y axis showing the change in speed and the other y axis showing the distance. See Attached Image. However, each data set was taken in one position, as shown on the x axis. How to do it?

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, i.e. 1,2 or 3.

Regards, Jer

+1
source share
2 answers

Is this what you want?

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

Mark the plotyydocumentation for the parameters.

enter image description here

0
source

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

0

Source: https://habr.com/ru/post/1616378/


All Articles