1

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

Jerry
  • 107
  • 3
  • 10
  • Isn't the x-axis in your picture the velocity? – knedlsepp Feb 21 '15 at 16:24
  • 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 Feb 21 '15 at 16:31
  • But what does the bulge mean then? Increased velocity? Then the x-axis IS velocity(+the offset for each data entry) – knedlsepp Feb 21 '15 at 16:32
  • 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 Feb 21 '15 at 16:35
  • 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 Feb 21 '15 at 16:40
  • possible duplicate of [Create an xy plot with two y axis](http://stackoverflow.com/questions/28634426/create-an-xy-plot-with-two-y-axis) – knedlsepp Feb 21 '15 at 16:52

2 Answers2

0

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

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • No because you are relating the data to the x axis. i.e. y is a function of x. In my case, x is just a stand alone value which will show the position where the data was recorded. Either position 1,2 or 3. You understand where my problem is now? – Jerry Feb 21 '15 at 16:33
  • also i tried plotyy but i just get either a dot or a vertical line when i try and plot the data against x – Jerry Feb 21 '15 at 16:33
  • 1
    No, I really don't understand. You have three curves, each corresponding to a velocity. Then you also have a velocity axis. And there's a second vertical axis. I can't really make sense out of that, sorry – Luis Mendo Feb 21 '15 at 16:56
0

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

Schorsch
  • 7,761
  • 6
  • 39
  • 65