2-x axes and 1-y axis

I would like to plot a figure having two x-axes at the bottom and the top of the figure, and one y-axis at the left of the figure.
I did an experiment where I am finding the relation between Intensiy and (time or temperature)
So I would like to have the time on the bottom x-axis and the corresponding temperature on the top x-axis. Where the intensity is common for both on the left y-axis.
Data as an example:
% Time in seconds
Time=[1 2 3 4 5 6 7 8 9 10]
Temperature=[23 10 0 -5]
Intensity=[2 2 4 3 7 9 5 6 8 2]
% where the temperature readings correspond to Time=[1 4 7 10] and Intensity=[2 3 5 2]

7 Comments

In fact this is just one function.
I would like to plot another one, that is:
Intensity as a function of Time
Temperature as a function of Time (where the temperature is on the top x-axis)
using the same Time axis
dpb
dpb on 6 Jun 2019
Edited: dpb on 6 Jun 2019
NB: There is no such thing as a figure with two x-axes and one y-axis -- to get two axes, there will always be two complete individual axes objects; you simply hide one that is duplicated. Also note you'll have to make the limits on the two axes coincide to prevent tick marks being dissonant between the two x axes.
In reality, for what you've described, unless the numeric values of temperature and intensity are of a similar magnitude and range, you'll probably end up needing two y axes to be able to display the data effectively.
Thank you for answering my question and for the illustration.
I have one more question : I do a cooling wxperiment such that the temperature decreases.
So, how can I make the data on the top axis decreasing while moving to the right. That is, the top left corner starts from room temperature (25) and the top right corner ends with (-172)??
dpb
dpb on 6 Jun 2019
I guess I don't follow what you want on which axis. If the y-value of the graph is temperature, then since 25 > -172, that's the normal direction of an axis as increasing to the top of the plot so with time on the x axis the trace will be decreasing....
No. In fact the y-axis is the Intensity.
So, I am talking about the top x-axis (Temperature). I want it to be decreasing while moving to the right starting from 23 and ending with -172
Then just reverse the direction for it...
hAx(2).XDir='reverse';
where hAx(2) is the handle to the second x-axis, presumed to be the target desired. You'll have to use whatever handle is the correct variable in your code that we've seen none for--hence the guessing about what you're trying to accomplish.
Or, of course, you can set addtiional parameters at the time you create the axes itself.

Sign in to comment.

Answers (1)

What about 'abusing' plotyy?
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
plotyy(x, y1, x, y2)
view(90, 90) % a single axis on the left, and two axes on top and bottom

10 Comments

Actually, I have deferent domains. Plotyy works if the domain is common.
You lost me. I suggest you rovide some real data and make a sketch of what you want.
Sorry for that. Here is an example similar to my data, I can't give exactly my data since it is thousands of points.
x1=Time=[0 3 6 9 15 33 50 44 67 100]
x2=Temperature=[23 0 -15 -70 -100 -170]
y1=Intensity(as a function of time)=[22 35 19 16 19 15 13 12 12 12]
y2=Intensity(as a function of Temperature)=[22 19 17 13 12 12]
I need to plot these is the same figure (I did it succesfully) but I need the left top of the top x-axis(x2) to be 23 and the top right to be -170
That is, I need the top x-axis to decrese as moving to the right.
dpb
dpb on 7 Jun 2019
"That is, I need the top x-axis to decrese as moving to the right."
I showed you above how to do that...but you haven't shown us specifically yet how you "I need to plot these is the same figure (I did it succesfully)..." so we have any idea of any specific code/syntax that matches what you've done.
[MQ's Answer moved to comment--dpb]
I am using the code from the following link:
how should I use
hAx(2).XDir='reverse';
in that code
dpb
dpb on 7 Jun 2019
Edited: dpb on 7 Jun 2019
Excepting they use ax1, ax2 for the axes handles, not an array hAx as my example did (I personally like the h prefix for handle and arrays to hold like handles as can be much more handy for subsequent get or set operations or to other functions expecting objec handles than individually-numbered variables).
I wrote in that prior response: "where hAx(2) is the handle to the second x-axis, presumed to be the target desired. You'll have to use whatever handle is the correct variable in your code...." which advice you did not heed.
Of course, since you know a priori you want that axis to be reverse direction, why not just set the parameter at the time you create it?
Yes you are right. Thank you, I didn't think that way. I will reverse the parameters and I am lucky since the top x-axis has a finate number of variables while the lower one has thousands.
Thank you very much for your help :))
dpb
dpb on 7 Jun 2019
No problem--glad to help! But computers do what we tell them to do, not necessarily what we mean! :)
I don't follow what you're referring to with the comment regarding number of variables on the two axes--how does that make any difference? Or, if it does, likely you've not using plot in the most efficient manner...
dpb
dpb on 7 Jun 2019
Actually, I have a limited number of readings corresponding to {Temperature,Intensity}.
While I have thousands for {Time,Intensity} and I am gothering them together from seperate videos.
So I can reverse the data on the top x-axis easily.
Thank you very much!
dpb
dpb on 7 Jun 2019
It still shouldn't make any difference at all how many variables there are -- the reverse direction is a property of the axis, not the data. Set it once and it's set for good...
We've possibly got a language barrier here in not following what you're trying to express...

Sign in to comment.

Categories

Asked:

on 6 Jun 2019

Commented:

dpb
on 7 Jun 2019

Community Treasure Hunt

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

Start Hunting!