COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

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

• Email
• 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 11/19/2009 11:12:33 AM

See related articles to this posting

```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
3280 Views

Similar Articles

11/30/2013 5:15:33 PM
page loaded in 49507 ms. (0)