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:
Adding a secondary axis to a figure

Subject: Adding a secondary axis to a figure

From: Jane

Date: 22 Sep, 2010 19:16:20

Message: 1 of 5

Hi,

I have concentration values from 6 sources over time, I have plotted these in a single figure as 6 seperate series. I now also want to add the speed values recorded over time to the same graph. Completely different data in a different range, the xdata is the same, so I want to add this information using a secondary y-axis on the right hand side of the figure.

I've found the function plotyy, but that seems to only cope with one series to the left and one to the right. I need 6 to the left and one to the right.

Any help?

Many thanks

Subject: Adding a secondary axis to a figure

From: Walter Roberson

Date: 22 Sep, 2010 19:31:55

Message: 2 of 5

On 10-09-22 02:16 PM, Jane wrote:

> I have concentration values from 6 sources over time, I have plotted
> these in a single figure as 6 seperate series. I now also want to add
> the speed values recorded over time to the same graph. Completely
> different data in a different range, the xdata is the same, so I want to
> add this information using a secondary y-axis on the right hand side of
> the figure.
>
> I've found the function plotyy, but that seems to only cope with one
> series to the left and one to the right. I need 6 to the left and one to
> the right.
>
> Any help?

ax = plotyy(... first of 6 for left..., ... desired right side);
hold(ax(1),'on')
now plot the other 5 specifying ax(1) as the axes to plot in to.


If the 6 sources can be aligned to have common X values, perhaps by padding
with NaN in places where one of the sources is shorter, then it becomes
easier: use the 6 different (possibly padded) sources as columns (not rows!)
of a single matrix, and specify that single matrix as the Y matrix; this will
draw all 6 at once, allowing you to use a single plotyy() command for both pieces.

Subject: Adding a secondary axis to a figure

From: Jane

Date: 22 Sep, 2010 19:50:21

Message: 3 of 5

Perfect!!

Thanks :D


> ax = plotyy(... first of 6 for left..., ... desired right side);
> hold(ax(1),'on')
> now plot the other 5 specifying ax(1) as the axes to plot in to.
>
>
> If the 6 sources can be aligned to have common X values, perhaps by padding
> with NaN in places where one of the sources is shorter, then it becomes
> easier: use the 6 different (possibly padded) sources as columns (not rows!)
> of a single matrix, and specify that single matrix as the Y matrix; this will
> draw all 6 at once, allowing you to use a single plotyy() command for both pieces.

Subject: Adding a secondary axis to a figure

From: Jimmy

Date: 9 Jan, 2013 16:23:08

Message: 4 of 5

"Jane T" wrote in message <i7dkm4$g4a$1@fred.mathworks.com>...
> Hi,
>
> I have concentration values from 6 sources over time, I have plotted these in a single figure as 6 seperate series. I now also want to add the speed values recorded over time to the same graph. Completely different data in a different range, the xdata is the same, so I want to add this information using a secondary y-axis on the right hand side of the figure.
>
> I've found the function plotyy, but that seems to only cope with one series to the left and one to the right. I need 6 to the left and one to the right.
>
> Any help?
>
> Many thanks

plotyy(x,[y1;y2;...;y6],x,y7);

Subject: Adding a secondary axis to a figure

From: dpb

Date: 9 Jan, 2013 21:59:53

Message: 5 of 5

On 1/9/2013 10:23 AM, Jimmy wrote:
> "Jane T" wrote in message <i7dkm4$g4a$1@fred.mathworks.com>...
...

>> I've found the function plotyy, but that seems to only cope with one
>> series to the left and one to the right. I need 6 to the left and one
>> to the right.
>>
...

>
> plotyy(x,[y1;y2;...;y6],x,y7);

And, of course, if the y1 thru y6 aren't of the same length, simply save
the (two) axes handles using the optional return arguments from plotyy
and then add directly to the appropriate axis.

Or, one can augment the shorter yn w/ NaN to the longest length and let
plotyy() deal w/ it automagically since plot() and friends ignore NaN
silently.

--

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