Multiple X-axes non linear to each other

I am aware that one can generate a plot with two x-axes, is it also posibble to generate such a plot with the x-axes non linear to each other.
I have a vector which can be plotted against both a distance and an angle, but the relationship between these two is not linear. Is it possible to plot the data against both variables in a single plot?
The vectors are not x,y,z, they are rather: y=data; x1=angle; x2=distance;
Using hold on/off doesn't really answer my question nor suit my data.
I have tried using the Multiple-X and Y axis approach from MATLAB docs (<http://www.mathworks.se/help/matlab/creating_plots/using-multiple-x-and-y-axes.html)>. Using the coding below, but the display allows for misinterpretation for the relationship between angle and distance hinting at a linear relationship. What I need is that in the plot below, the axes are so that the curves overlap.
distance=0:12:9000;
angle=atan(distance/1000)*(180/(2*pi));
data=logspace(0,1,length(distance));
x1 = angle;
y1 = data;
x2 = distance;
y2 = data;
figure;
l1 = line(x1,y1,'Color','r');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
hl2 = line(x2,y2,'Color','k','Parent',ax2);

3 Comments

You do not need to post all these data, just tell what are the sizes of your vectors. Or post a short sample of your data
Noted!, I've made nicer looking vectors
I am looking for something similar to this, but for the x-axes only: http://i.stack.imgur.com/88llX.gif

Sign in to comment.

Answers (1)

If your vectors are x, y and z
plot3(x,y,z)
In your case
plot3(distnace,angle,data)
%or maybe you are looking for two plots
plot(distance,data,'g')
hold on
plot(angle,data,'r')
hold off

7 Comments

Marina
Marina on 15 Jul 2013
Edited: Marina on 15 Jul 2013
refer to updated question
The relation between your data (linear or not) is not important, since you want just have the plots. Also, please remove the data you've posted above. They are not helpful or at least post 10 lines of data.
You can use plotyy
plotyy(x1,y1,x2,y2)
Nope, been there, done that, that is not the plot that I am looking for. The relationship between the data is of the outmost importance and I need it to be expressed through the plot.
You have 3 variables:data, angle, and distance. What do you want to plot?
data vs angle AND data vs distance in the same plot BUT keeping the proportionality between angle and distance and by this I mean having either angle or distance (I dont really mind which) NOT being a linear axis, meaning, NOT going from 0 to its maximum at equal spacing but rather at the spacing dictated by their proportionality.
Quirky example: run the code I put on my question above
in the plot it seems as if distance=5000 equal an angle=25, when in reality, distance=5000 corresponds to angle=39.3549deg. I want a plot that reflects this.
Then, what you want to do is to plot (data,angle), then just add a second x-axis (distance). Is that what you want?
Yes BUT that the second axis reflects the relationship between angle and distance.
Because I do know how and have done already a plot with two x-axes (That's the code attached to the question), whats missing, is for the second axis to reflect its relationship with the primary axis.

Sign in to comment.

Products

Asked:

on 15 Jul 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!