Thread Subject: graph culture with 'plotyy': color and line style, etc

Subject: graph culture with 'plotyy': color and line style, etc

From: Nancy Hammond

Date: 17 Aug, 2009 19:05:17

Message: 1 of 12

When you create two axes with plotyy , how do you specifiy the color and style attrubutes?


Also I find the first axis locked so that I can't edit its properties after the figure is created

[ax1,hl,hright]= plotyy(T,ss,T,c) %’b:','LineWidth',4)
hold on
[ax2,h2,hleft]= plotyy(T,sfs,T,cf) %'b:','LineWidth',4)
hold on

I I use line instead of plotyy, I use 'Color','b',... which works

Thanks,

Nancy

Subject: graph culture with 'plotyy': color and line style, etc

From: dpb

Date: 17 Aug, 2009 20:53:34

Message: 2 of 12

Nancy Hammond wrote:
> When you create two axes with plotyy , how do you specifiy the color and style attrubutes?
>
>
> Also I find the first axis locked so that I can't edit its properties after the figure is created
>
> [ax1,hl,hright]= plotyy(T,ss,T,c) %’b:','LineWidth',4)
> hold on
> [ax2,h2,hleft]= plotyy(T,sfs,T,cf) %'b:','LineWidth',4)
> hold on
>
> I I use line instead of plotyy, I use 'Color','b',... which works

> [AX,H1,H2] = plotyy(...) returns the handles of the two axes created > in AX and the handles of the graphics objects from each plot in H1
and H2

get(H1) will return all the settable properties including 'LineStyle',
'Color', 'Symbol' for the line

Note that in the return values as you've written them above the two
lines associated w/ the left axes are h1,h2 and the right axes hright,hleft.

It appears you may be misinterpreting which handle is which object...

--

Subject: graph culture with 'plotyy': color and line style, etc

From: Nancy Hammond

Date: 18 Aug, 2009 11:46:02

Message: 3 of 12

Thank you, this worked. But how to correctly assign ylabel to each axis? The commented out '%' are what didn't work:

[ax,hl,hr]= plotyy(T,ss,T,c)
hold on
get(ax(1))
yhl = ylabel('Optimal inventory size (hundreds)','FontSize',16,'FontName','Times-Roman');
%set(ax(1),'YLabel',yhl)
%set(get(ax(1)),'YLabel',yhl)

get(ax(2))
yhr = ylabel('Inventory cost ($hundreds)','FontSize',16,'FontName','Times-Roman')
%set(ax(2),'YLabel',yhr)
%set(get(ax(2)),'YLabel',yhr)
set(hl,'Color','b','LineStyle','-','LineWidth',3);
xlabel('Year','FontSize',16,'FontName','Times-Roman');
set(hr,'Color','r','LineStyle','-','LineWidth',3);



dpb <none@non.net> wrote in message <h6cg81$rv3$1@news.eternal-september.org>...
> Nancy Hammond wrote:
> > When you create two axes with plotyy , how do you specifiy the color and style attrubutes?
> >
> >
> > Also I find the first axis locked so that I can't edit its properties after the figure is created
> >
> > [ax1,hl,hright]= plotyy(T,ss,T,c) %’b:','LineWidth',4)
> > hold on
> > [ax2,h2,hleft]= plotyy(T,sfs,T,cf) %'b:','LineWidth',4)
> > hold on
> >
> > I I use line instead of plotyy, I use 'Color','b',... which works
>
> > [AX,H1,H2] = plotyy(...) returns the handles of the two axes created > in AX and the handles of the graphics objects from each plot in H1
> and H2
>
> get(H1) will return all the settable properties including 'LineStyle',
> 'Color', 'Symbol' for the line
>
> Note that in the return values as you've written them above the two
> lines associated w/ the left axes are h1,h2 and the right axes hright,hleft.
>
> It appears you may be misinterpreting which handle is which object...
>
> --
>

Subject: graph culture with 'plotyy': color and line style, etc

From: dpb

Date: 18 Aug, 2009 14:42:46

Message: 4 of 12

Nancy Hammond wrote:

...top posting repaired--please don't do that; makes following
conversation very difficult...

>
> dpb <none@non.net> wrote in message <h6cg81$rv3$1@news.eternal-september.org>...
>> Nancy Hammond wrote:
>>> When you create two axes with plotyy , how do you specifiy the color and style attrubutes?
>>>
...
>> get(H1) will return all the settable properties including 'LineStyle',
>> 'Color', 'Symbol' for the line
>>
>> Note that in the return values as you've written them above the two
>> lines associated w/ the left axes are h1,h2 and the right axes hright,hleft.
>>
>> It appears you may be misinterpreting which handle is which object...
>>

 > Thank you, this worked. But how to correctly assign ylabel to each >
axis? The commented out '%' are what didn't work:
...

doc axes

axes(ax(1)); ylabel('Left label')
axes(ax(2)); ylabel('Right label')

--

Subject: graph culture with 'plotyy': color and line style, etc

From: dpb

Date: 18 Aug, 2009 14:56:58

Message: 5 of 12

dpb wrote:
..

> axes(ax(1)); ylabel('Left label')
> axes(ax(2)); ylabel('Right label')

BTW, the indirect route would look something like

set(get(ax(1),'ylabel'), 'String', 'New Left Label')

which explains why you want to save the axes handles and use the
higher-level interface routines... :)

--

Subject: graph culture with 'plotyy': color and line style, etc

From: Steven Lord

Date: 18 Aug, 2009 15:45:49

Message: 6 of 12


"dpb" <none@non.net> wrote in message
news:h6eesp$rai$1@news.eternal-september.org...
> Nancy Hammond wrote:
>
> ...top posting repaired--please don't do that; makes following
> conversation very difficult...
>
>>
>> dpb <none@non.net> wrote in message
>> <h6cg81$rv3$1@news.eternal-september.org>...
>>> Nancy Hammond wrote:
>>>> When you create two axes with plotyy , how do you specifiy the color
>>>> and style attrubutes?
>>>>
> ...
>>> get(H1) will return all the settable properties including 'LineStyle',
>>> 'Color', 'Symbol' for the line
>>>
>>> Note that in the return values as you've written them above the two
>>> lines associated w/ the left axes are h1,h2 and the right axes
>>> hright,hleft.
>>>
>>> It appears you may be misinterpreting which handle is which object...
>>>
>
> > Thank you, this worked. But how to correctly assign ylabel to each >
> axis? The commented out '%' are what didn't work:
> ...
>
> doc axes
>
> axes(ax(1)); ylabel('Left label')
> axes(ax(2)); ylabel('Right label')

Rather than forcing each axes to become active, I'd use the syntax for
YLABEL that accepts an axes handle:

    ylabel(ax(1), 'Left label')

--
Steve Lord
slord@mathworks.com

Subject: graph culture with 'plotyy': color and line style, etc

From: Nancy Hammond

Date: 18 Aug, 2009 17:56:03

Message: 7 of 12

dpb <none@non.net> wrote in message <h6efn8$tuc$1@news.eternal-september.org>...
> dpb wrote:
> ..
>
> > axes(ax(1)); ylabel('Left label')
> > axes(ax(2)); ylabel('Right label')
>
> BTW, the indirect route would look something like
>
> set(get(ax(1),'ylabel'), 'String', 'New Left Label')
>
> which explains why you want to save the axes handles and use the
> higher-level interface routines... :)
>
> Thank you
nh

Subject: graph culture with 'plotyy': color and line style, etc

From: Paul Mennen

Date: 18 Aug, 2009 20:23:05

Message: 8 of 12

"Nancy Hammond" wrote:
> When you create two axes with plotyy , how do you
> specifiy the color and style attrubutes?

"Nancy Hammond" wrote
> Thank you, this worked. But how to correctly assign ylabel to each axis?

Of the thousands of Matlab functions, I've noticed that plotyy must be the most confusing of them all based on the number of questions like this we get on the newsgroup. It's the same year after year so it is amazing to me that TMW doesn't get the hint.

Why does this function confuse so many users? ... Perhaps because the interface is cryptic, not well documented, and for all but the most simplistic plots, required multiple commands (plotyy, legend, axis, axes, grid, title, ylabel, colordef, datacursormode, set, etc.). This means that there is no one place in the documentation that tells you how to actually create the plots you need. And you pretty much need to understand the arcane handle graphics concepts to get anything to work right. Worst of all, there are few examples to demonstrate the many ways to use plotyy.

So several years ago I tried to take this sad state of affairs into my own hands by writing a new interface to the Matlab graphics engine. I called it simply "plt.m" (complete source code now available under the BSD license at http://www.mathworks.com/matlabcentral/fileexchange/4936).

One of the main philosophical differences between plt and Matlab's plot/plotyy is that everything can be specified using a single call to plt. You can specify as many traces as you want on the command line, i.e. plt(x1,y1,x2,y2,x3,y3,x4,y4) and plt will plot them using all its defaults. As with plot, you can use matrices to define several lines at once. The command above will plot all four traces on the left hand axis, but for example to assign traces 2 and 4 to the right axis, simply add 'Right',[2 4] to the argument list. Even a legend is created for you (using the default trace names Line1, Line2, ...) and you can use the legend to selectively turn on and off any of the traces. To give more meaningful names to the traces, use the 'TraceID' argument. By default cursor objects are provided, but of course there are parameters to modify them or remove them all together. Many other options
as well, too numerous to mention here. Just type "plt help" for a parameter list, or "help plt" for the complete documentation (or click on the "help" tag at the left edge of any plot created with plt).

At the same time as cleaning up the interface, I tried to change some of my pet peeves with the native plot/plotyy. One of the biggies was the grid lines. I couldn't set the grid line color independent from the axis color, resulting in garish grid lines that often over powered the traces. (Either that or live with barely readable tick marks and labels). So of course I made the default grid lines much more subtle, and if you don't like the default grid color, you can change it independently to anything you like (as with any color on the plot). Another biggie was the cumbersome methods of panning or zooming the plots compared to other plotting software, so I worked hard on making that easier and more intuitive.

Although the default settings I've chosen won't please everyone, the feedback I've received indicates that this experiment has largely been a success. To make the effort even more of a success I hope you will try this function and let me know what you like and what could be improved. If there is anything even slightly confusing in the help file, please let me know about that too. Also take a look at the examples in the plt\demo folder and let me know which if any you found most useful and which if any should be added.

Thanks.
~Paul Mennen

p.s. Feel free to contact me with any comments or questions via email:

paul (at) mennen (dot) org

Subject: graph culture with 'plotyy': color and line style, etc

From: Susan Hough

Date: 20 Aug, 2009 18:50:21

Message: 9 of 12

"Paul Mennen" <nospam@mennen.org> wrote in message
> So several years ago I tried to take this sad state of affairs into my own hands by writing a new interface to the Matlab graphics engine. I called it simply "plt.m" (complete source code now available under the BSD license at http://www.mathworks.com/matlabcentral/fileexchange/4936).

That looks interesting, but when I click on that link it claims that it was mistyped. Is that the correct link?

Thanks
- susan

Subject: graph culture with 'plotyy': color and line style, etc

From: dpb

Date: 20 Aug, 2009 19:04:10

Message: 10 of 12

Steven Lord wrote:
...
> Rather than forcing each axes to become active, I'd use the syntax for
> YLABEL that accepts an axes handle:
>
> ylabel(ax(1), 'Left label')

So would I if my version supported same... :(

--

Subject: graph culture with 'plotyy': color and line style, etc

From: dpb

Date: 20 Aug, 2009 19:13:40

Message: 11 of 12

Susan Hough wrote:
> "Paul Mennen" <nospam@mennen.org> wrote in message
...

>> http://www.mathworks.com/matlabcentral/fileexchange/4936).
>
> That looks interesting, but when I click on that link it claims that
> it was mistyped. Is that the correct link?
...

Worked here...

--

Subject: graph culture with 'plotyy': color and line style, etc

From: Paul Mennen

Date: 21 Aug, 2009 04:43:03

Message: 12 of 12

dpb <none@non.net> wrote in message <h6k7gv$hie$1@news.eternal-september.org>...
> Susan Hough wrote:
> > "Paul Mennen" <nospam@mennen.org> wrote in message
> ...
>
> >> http://www.mathworks.com/matlabcentral/fileexchange/4936).
> >
> > That looks interesting, but when I click on that link it claims that
> > it was mistyped. Is that the correct link?
> ...
>
> Worked here...

Oops, I do see the problem. There is some extra punctuation at the end of the link that I included accidentally, so if you just click on it, it probably won't work. The link should have ended with the four digits. This should work:

http://www.mathworks.com/matlabcentral/fileexchange/4936

Or you can easily find it by going to the file exchange and search for "plt".

~Paul

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
graph culture w... Nancy Hammond 17 Aug, 2009 15:09:03
rssFeed for this Thread

Contact us at files@mathworks.com