Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: plotyy&annotating

Subject: plotyy&annotating

From: Wu Zhiyong

Date: 19 Apr, 2008 08:13:02

Message: 1 of 4

well,the data are as followed:
[x,y1],[x,y2],[x,y3];
I want to plot three lines. plot y1,y2 for the left
axes,and plot y3 for the right axes.
It seams that we can just plot 2 lines with the
function "plotyy".
I add another "plot",but I failed to annotate the figure.
my code are as followed:

[Ax,H1,H2]=plotyy(x,y1,x,y3);
hold on
H3=plot(x,y2);
set(gca,'XTick',[0 3 6 9 12 15 18],'XTicklabel',[08 11 14
17 20 23 02])
legend('modis','usgs','diff')

I can't get the right legend and XTicklabel.

Do you have any good ideal?
any suggestion is appreciated!
Thanks!

Subject: Re: plotyy&annotating

From: Anh Huy Phan

Date: 19 Apr, 2008 15:20:03

Message: 2 of 4

"Wu Zhiyong" <wuzhiyong_163@163.com> wrote in message
<fuc9ie$qp7$1@fred.mathworks.com>...
> well,the data are as followed:
> [x,y1],[x,y2],[x,y3];
> I want to plot three lines. plot y1,y2 for the left
> axes,and plot y3 for the right axes.
> It seams that we can just plot 2 lines with the
> function "plotyy".
> I add another "plot",but I failed to annotate the figure.
> my code are as followed:
>
> [Ax,H1,H2]=plotyy(x,y1,x,y3);
> hold on
> H3=plot(x,y2);
> set(gca,'XTick',[0 3 6 9 12 15 18],'XTicklabel',[08 11 14
> 17 20 23 02])
> legend('modis','usgs','diff')
>
> I can't get the right legend and XTicklabel.
>
> Do you have any good ideal?
> any suggestion is appreciated!
> Thanks!
>


Something likes this
[Ax,H1,H2]=plotyy(x,[y1;y2],x,y3);
legend([H1;H2],{'modis','usgs','diff'})
set(Ax(1),'XTick',[0 3 6 9 12 15 18],'XTicklabel',[08 11 14
17 20 23 02])
set(Ax(1),'XTick',[])


Anh Huy Phan
BSI - RIKEN

Subject: Re: plotyy&annotating

From: Steven Lord

Date: 21 Apr, 2008 02:57:34

Message: 3 of 4


"Wu Zhiyong" <wuzhiyong_163@163.com> wrote in message
news:fuc9ie$qp7$1@fred.mathworks.com...
> well,the data are as followed:
> [x,y1],[x,y2],[x,y3];
> I want to plot three lines. plot y1,y2 for the left
> axes,and plot y3 for the right axes.
> It seams that we can just plot 2 lines with the
> function "plotyy".
> I add another "plot",but I failed to annotate the figure.
> my code are as followed:
>
> [Ax,H1,H2]=plotyy(x,y1,x,y3);
> hold on
> H3=plot(x,y2);
> set(gca,'XTick',[0 3 6 9 12 15 18],'XTicklabel',[08 11 14
> 17 20 23 02])
> legend('modis','usgs','diff')
>
> I can't get the right legend and XTicklabel.
>
> Do you have any good ideal?
> any suggestion is appreciated!
> Thanks!

I'd use LINE rather than PLOT in this case:

H3 = line(x, y2, 'Parent', Ax(1))

Then pass in a vector of handles as the first input to LEGEND:

legend([H1, H2, H3], ...)

--
Steve Lord
slord@mathworks.com


Subject: Re: plotyy&annotating

From: Paul Mennen

Date: 21 Apr, 2008 08:02:02

Message: 4 of 4

> Something likes this
> [Ax,H1,H2]=plotyy(x,[y1;y2],x,y3);
> legend([H1;H2],{'modis','usgs','diff'})
> set(Ax(1),'XTick',[0 3 6 9 12 15 18],
> 'XTicklabel',[08 11 14 17 20 23 02])
> set(Ax(1),'XTick',[])
> Anh Huy Phan

> I'd use LINE rather than PLOT in this case:
> H3 = line(x, y2, 'Parent', Ax(1))
> Then pass in a vector of handles as the first input to
> LEGEND: legend([H1, H2, H3], ...)
> Steve Lord

I don't see why people should have to put up with so
cryptic an interface as plotyy. One shouldn't have to
mess with all these handles to do something so basic
as to plot 3 lines with a legend.

I've developed an alternative interface (called plt)
for this type of thing. For instance the above would be:

plt(x,[y1;y2;y3],'Right',3,...
    'TraceID',{'modis','usgs','diff'});

The 'Right' parameter tells plt to put the 3rd trace
on the right hand axis. (You still would need the
set gca command however to get the unusual x-axis ticks.)

Of course, there are many more options in plt for making
the plot appear as you prefer - see plt.chm to see what
they are. (Note: available from the file exchange).

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
plotyyannotating Wu Zhiyong 19 Apr, 2008 04:16:51
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics