How to create a second x-axis on top of plot?

  • Follow


I have a 2d plot, where I'm plotting units in nm on the x-axis. I want
to calculate the corresponding electron-volt value, and display this
value on the x axis on top of the plot. How can I do this? I am
attempting to plot both datasets (which has the exact same spots in
the graph), and have both eV and nm scaling show in the figure, one on
top, and one below the plot area.. how can I do this?
0
Reply jon.skarpeteig (2) 11/19/2009 11:12:33 AM

Jon <jon.skarpeteig@gmail.com> wrote in message <0d4f5212-09e2-4e17-87ab-ad5563c152e6@d21g2000yqn.googlegroups.com>...
> I have a 2d plot, where I'm plotting units in nm on the x-axis. I want
> to calculate the corresponding electron-volt value, and display this
> value on the x axis on top of the plot. How can I do this? I am
> attempting to plot both datasets (which has the exact same spots in
> the graph), and have both eV and nm scaling show in the figure, one on
> top, and one below the plot area.. how can I do this?

Hi Jon, here is one way, plotting a cosine with seconds on the bottom x-axis and milliseconds on the top x-axis.

t =0:(1/Fs):0.1; %seconds
t1 = t.*1000; % msec
Fs = 1000;
hLine1 = line(t,y,'color','k');
Ax1 = gca;
Ax2 = axes('Position',get(Ax1,'Position'),...
           'XAxisLocation','top');
hLine2 = line(t1,y,'color','k','parent',Ax2);

Hope that helps,
Wayne
0
Reply Wayne 11/19/2009 12:53:06 PM


"Wayne King" <wmkingty@gmail.com> wrote in message <he3f3i$cb4$1@fred.mathworks.com>...
> Jon <jon.skarpeteig@gmail.com> wrote in message <0d4f5212-09e2-4e17-87ab-ad5563c152e6@d21g2000yqn.googlegroups.com>...
> > I have a 2d plot, where I'm plotting units in nm on the x-axis. I want
> > to calculate the corresponding electron-volt value, and display this
> > value on the x axis on top of the plot. How can I do this? I am
> > attempting to plot both datasets (which has the exact same spots in
> > the graph), and have both eV and nm scaling show in the figure, one on
> > top, and one below the plot area.. how can I do this?
> 
> Hi Jon, here is one way, plotting a cosine with seconds on the bottom x-axis and milliseconds on the top x-axis.
> 
> t =0:(1/Fs):0.1; %seconds
> t1 = t.*1000; % msec
> Fs = 1000;
> hLine1 = line(t,y,'color','k');
> Ax1 = gca;
> Ax2 = axes('Position',get(Ax1,'Position'),...
>            'XAxisLocation','top');
> hLine2 = line(t1,y,'color','k','parent',Ax2);
> 
> Hope that helps,
> Wayne
Sorry Jon, I noticed that I forgot to paste in the cosine, and to declare Fs before constructing the time vector:

Fs = 1000;
t =0:(1/Fs):0.1; %seconds
t1 = t.*1000; % msec
y = cos(2*pi*100*t);
hLine1 = line(t,y,'color','k');
Ax1 = gca;
Ax2 = axes('Position',get(Ax1,'Position'),...
           'XAxisLocation','top');
hLine2 = line(t1,y,'color','k','parent',Ax2);

Wayne
0
Reply Wayne 11/19/2009 2:41:22 PM

2 Replies
2650 Views

(page loaded in 0.034 seconds)

Similiar Articles:













7/19/2012 7:13:32 PM


Reply: