help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with legend


From: Ben Abbott
Subject: Re: help with legend
Date: Mon, 16 Jan 2012 08:24:07 -0500

On Jan 15, 2012, at 9:58 PM, Valmor de Almeida wrote:

> On 01/15/2012 08:10 PM, Ben Abbott wrote:
>> 
>> On Jan 15, 2012, at 2:35 PM, Ben Abbott wrote:
>> 
>>> On Jan 15, 2012, at 12:48 PM, Valmor de Almeida wrote:
>>> 
>>>> Hello,
>>>> 
>>>> I am trying to customize legends on a plotyy axes/lines but I am not
>>>> able to. Here are the commands:
>>>> 
>>>> [ax, h1, h2] = plotyy(x1,y1, x2,y2, @plot, @plot);
>>>> 
>>>> legend(h1,y1Label,"location",'south',"fontname",'Helvetica');
>>>> 
>>>> legend(h2,y2Label,"location",'northeast',"fontname",'Helvetica');
>>>> 
>>>> Only the first legend shows up and the font is Courier which I am unable
>>>> to change. Also the text in the legend precedes the key which I would
>>>> like to invert using 'right' but it does not work either.
>>>> 
>>>> I am using octave-3.4.0. Would anyone have an example?
>>>> 
>>>> Thanks,
>>>> 
>>>> --
>>>> Valmor
>>>> 
>>>> PS: In the above command I also tried legend(ax(1),...) and it does not
>>>> make a difference.
>>> 
>>> Octave tries to duplicate Matlab's implementation of plotyy and legend. 
>>> 
>>>     x1 = 0:5:10;
>>>     x2 = 0:10;
>>>     y1 = rand (size (x1));
>>>     y2 = rand (size (x2));
>>>     [ax, h1, h2] = plotyy (x1, y1, x2, y2, @plot, @plot);
>>>     y1Label = "y1";
>>>     y2Label = "y2";
>>> 
>>> The command below should produce the desired legend (please check, the 
>>> implementation may have changed since 3.4.0).
>>> 
>>>     legend ([h1, h2], {y1Label, y2Label}, "location", "south")
>>> 
>>> The commands below should also work, but currently reverse the legend 
>>> entries.
>>> 
>>>     legend ({y1Label, y2Label}, "location", "south")
>>> 
>>>     legend (y1Label, y2Label, "location", "south");
>>> 
>>> I've entered a bug report in the tracker.
>>> 
>>>     https://savannah.gnu.org/bugs/?35314
>>> 
>>> Regarding "Fontsize", the legend function doesn't accept property 
>>> names/values as input.
>>> 
>>> To change the fontname, the legend command returns the handle to the 
>>> legend. You can change its fontname property directly.
>>> 
>>>     h = legend ([h1, h2], {y1Label, y2Label}, "location", "south")
>>>     set (h, "fontname",'Helvetica") 
>>> 
>>> Ben
>> 
>> I've attached a changeset to the bug-tracker that fixes the legend command 
>> so that all three versions below work the same.
>> 
>>      legend ([h1, h2], {y1Label, y2Label}, "location", "south")
>> 
>>      legend ({y1Label, y2Label}, "location", "south")
>> 
>>      legend (y1Label, y2Label, "location", "south");
>> 
>> The tracker link is below.
>> 
>>      https://savannah.gnu.org/bugs/index.php?35314
>> 
>> Ben
>> 
> 
> Thanks Ben,
> 
> None of the forms work for my version 3.4.0.
> 
> error:   /usr/share/octave/3.4.0/m/plot/__gnuplot_print__.m at line 170,
> column 5
> 
> The handle to set the fontname does not work either. Which version are
> you using? 3.4.3 is the highest I will be able to go unless I compile
> octave myself.
> 
> --
> Valmor


The error from __gnplot_print__() is something different. That function only is 
called by print().

Running 3.4.0, I checked ...

        x = 0:10;
        plotyy (x, sqrt(x), x, x.^2);
        h = legend ("root", "squared");
        set (h, "fontname", "Courier")
        print test.eps
        print test.png

... I encountered no errors, and obtained the expected results.

Can you provide a simple example that produces the __gnuplot_print__ error ?

Ben






reply via email to

[Prev in Thread] Current Thread [Next in Thread]