1
votes

I'm trying to create an xy plot with two y axis. I have three sets of velocity data. Im trying to create a plot with one y axis showing the variation of velocity and the other y axis showing distance. Please see the attached image. However, each set of data was taken at one position as seen on the x axis. How to I do this?

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.

Regards, Jer

2
Isn't the x-axis in your picture the velocity? - knedlsepp
No the x axis is just the position where i recorded the data. I don't know how to link that with my velocity data. - Jerry
But what does the bulge mean then? Increased velocity? Then the x-axis IS velocity(+the offset for each data entry) - knedlsepp
I see where you are coming from. The bulge would be a decrease in velocity. In hind sight I'm not sure this is possible as you pointed out, the bulge in the velocity data wont line up with the point value on the x axis and will cause problems - Jerry
I think you should rethink this plot. What you are asking can be achieved with Luis' answer, but I don't think you want what you are asking for, as the velocity in this plot is actually the x-axis. (I think that you should also rethink your statement that the bulge should be a decrease. Usually going to the right of a plot means INcrease) - knedlsepp

2 Answers

0
votes

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

Check plotyy documentation for options.

enter image description here

0
votes

You can normalize your velocity data and plot that at distinct x-locations. However, once your velocity changes are too large, expect the curves to overlap.

% 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])

And you'll end up with this plot:

xlocplot