Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
timeseries multiple axes

Subject: timeseries multiple axes

From: Raphael Attie

Date: 19 Jan, 2010 14:24:03

Message: 1 of 5

Hi,

I'm having a hard time plotting 2 different samples from 2 different timeseries, in multiple axes within the same figure.

Here is the example below, with "xrt_ts2" and "nfi_ts2" sharing the same time vector. I'm trying to use the multiple axes to plot one in a right Y-axis and the other one in a left Y-axis. But whatever I do, with, without hold on, using 'Parent', etc... the second plot erase the previous plot. Even the 2nd ax is erased right after its creation, after invoking the 2nd plot... See below :

f2=figure(2);
cla
h2=plot(xrt_ts2,'r-');
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
hold on
ax2 = axes('Position',get(ax1,'Position'),...
           'XAxisLocation','top',...
           'YAxisLocation','right',...
           'Color','none',...
           'XColor','k','YColor','k');
       set(f2,'CurrentAxes',ax2)

plot(nfi_ts2)

Subject: timeseries multiple axes

From: Ramita S.

Date: 19 Jan, 2010 15:06:04

Message: 2 of 5

Is "plotyy" what you are looking for?

"Raphael Attie" <attie@mps.mpg.de> wrote in message <hj4fa3$r24$1@fred.mathworks.com>...
> Hi,
>
> I'm having a hard time plotting 2 different samples from 2 different timeseries, in multiple axes within the same figure.
>
> Here is the example below, with "xrt_ts2" and "nfi_ts2" sharing the same time vector. I'm trying to use the multiple axes to plot one in a right Y-axis and the other one in a left Y-axis. But whatever I do, with, without hold on, using 'Parent', etc... the second plot erase the previous plot. Even the 2nd ax is erased right after its creation, after invoking the 2nd plot... See below :
>
> f2=figure(2);
> cla
> h2=plot(xrt_ts2,'r-');
> ax1 = gca;
> set(ax1,'XColor','r','YColor','r')
> hold on
> ax2 = axes('Position',get(ax1,'Position'),...
> 'XAxisLocation','top',...
> 'YAxisLocation','right',...
> 'Color','none',...
> 'XColor','k','YColor','k');
> set(f2,'CurrentAxes',ax2)
>
> plot(nfi_ts2)

Subject: timeseries multiple axes

From: Raphael Attie

Date: 19 Jan, 2010 15:20:21

Message: 3 of 5

Hi,

Plotyy is not part of the method of the timeseries-class objects. Thus it is not permitted to plot it.

So far, the only workaround I have is to extract separately the time vector and data using, in my example, xrt_ts2.data and getabstime(xrt_ts2) (same for nfi_ts2), to recover the right Xtick-labels. But it's a bit sad, i thought the whole point of using timeseries class would be to avoid these sort of things.
Any better idea than this workaround is welcome.

Thanks

"Ramita S." <rsuteekarn@gmail.com> wrote in message <hj4hos$886$1@fred.mathworks.com>...
> Is "plotyy" what you are looking for?
>
> "Raphael Attie" <attie@mps.mpg.de> wrote in message <hj4fa3$r24$1@fred.mathworks.com>...
> > Hi,
> >
> > I'm having a hard time plotting 2 different samples from 2 different timeseries, in multiple axes within the same figure.
> >
> > Here is the example below, with "xrt_ts2" and "nfi_ts2" sharing the same time vector. I'm trying to use the multiple axes to plot one in a right Y-axis and the other one in a left Y-axis. But whatever I do, with, without hold on, using 'Parent', etc... the second plot erase the previous plot. Even the 2nd ax is erased right after its creation, after invoking the 2nd plot... See below :
> >
> > f2=figure(2);
> > cla
> > h2=plot(xrt_ts2,'r-');
> > ax1 = gca;
> > set(ax1,'XColor','r','YColor','r')
> > hold on
> > ax2 = axes('Position',get(ax1,'Position'),...
> > 'XAxisLocation','top',...
> > 'YAxisLocation','right',...
> > 'Color','none',...
> > 'XColor','k','YColor','k');
> > set(f2,'CurrentAxes',ax2)
> >
> > plot(nfi_ts2)

Subject: timeseries multiple axes

From: Rob Campbell

Date: 19 Jan, 2010 16:28:02

Message: 4 of 5

You need to set the background colour of the second set of axes /after/ you plot the data on it. Plot seems to reset this. Just do "set(ax2, 'Color','none')" after your last plot command and it should do what you want.

You may find that the overlay on the two axes isn't perfect when you print to file. To fix this, just fiddle with the paperposition property of the figure until it works right. It is possible to get this work.

Rob

Subject: timeseries multiple axes

From: Rob Campbell

Date: 19 Jan, 2010 16:38:04

Message: 5 of 5

p.s. I'm not sure if this will work with a time-series object, but it ought to. The problem you describe occurs for non-time series data.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us