bugGNU Octave - Bugs: bug #33757, Legend using DisplayName not...

 
 

bug #33757: Legend using DisplayName not displayed

Submitter:  None
Submitted:  Tue 12 Jul 2011 05:43:32 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  Fixed Assigned to:  None
Originator Name:  Burkart Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.4.2
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 26 Sep 2012 12:40:42 AM UTC, comment #9: 

Ben, that's awesome about your child.  I expect you will be getting very little sleep for the next 3-6 months.

I'm not sure where your legend2.m script came from.  When I diff it against the one in the Mercurial repository there are a lot of changes.  When I use the one in the repository there is a single mismatch for the example with 'legend location south'.  I'll work on that one.

Rik <rik5>
Group administrator
Tue 25 Sep 2012 10:21:44 PM UTC, comment #8: 

Rik,

I still see some problems.  I've attached  test script and what Matlab gives.

This week has been up in the air for me (waiting for the birth of my 1st child).  So I had some time to experiment ... my free time is soon to end I suspect.

I any event, I've also attached a legend2.m and the result it gives.  There is a good possibility that something is broken in legend2.m, but all the demos look ok ... even though there are some differences when compared to Matlab.


(file #26633, file #26634, file #26635, file #26636)

Ben Abbott <bpabbott>
Group Member
Tue 25 Sep 2012 08:54:19 PM UTC, comment #7: 

Ben, check out this changeset of mine (http://hg.savannah.gnu.org/hgweb/octave/rev/015cc3d1f389).  I think it fixes the Matlab compatability issue with DisplayName.

Rik <rik5>
Group administrator
Tue 25 Sep 2012 12:18:00 AM UTC, comment #6: 

I'd say that a new bug report should be opened since the behavior is different.  The bug I fixed was with the behavior of 'show' and 'toggle'.  The stuff that you have uncovered is about how the DisplayName property is implemented.

A partial fix doesn't seem too bad.  Basically, IF there are no legend names provided AND there are no DisplayName properties on the graphics objects found, then use data1, data2, ..., dataN.  Maybe you can verify this again, but why when the legend is created isn't the DisplayName property updated?  See the code below, which in Octave definitely sets the DisplayName property.


h = plot (1:10);
get (h, 'displayName')
ans =
hl = legend (h, 'mydata');
get (h, 'displayName')
ans = mydata


The other thing to do is to try and figure out where Matlab is holding the labels for the legend if it isn't in the displayName property.  My guess is the 'string' property of the legend.  Try the following in Matlab.


h = plot (rand (3));
hl = legend ('show');
get (hl, 'string')


If this is where they are storing things then the fix isn't that hard.  Octave would simply need to write the data1, data2, ... labels into a cellstr in the 'string' property of the legend AND not update the DisplayName properties of the children.

Rik <rik5>
Group administrator
Mon 24 Sep 2012 11:38:45 PM UTC, comment #5: 

hmmm ... the following


h = plot (rand (3));
legend (h([1,3]), 'location', 'north')


is equivalent to


h = plot (rand (3));
legend (h([1,3]), {'data1', 'data2'}, 'location', 'north')


Not likely a quick fix ?

Should this be reopened ?

Ben Abbott <bpabbott>
Group Member
Mon 24 Sep 2012 11:18:13 PM UTC, comment #4: 

Rik,

In Matlab, I tried


>> h = plot (rand (3))

h =

  175.0022
  176.0012
  177.0012

>> get (h, 'displayName')

ans =

    ''
    ''
    ''

>> legend show
>> get (h, 'displayName')

ans =

    ''
    ''
    ''


and obtained the attached result.  Since you've just looked over the code, do you see an easy way to implement compatibility and also properly handle cases like below?


h = plot (rand (3));
legend (h([1,3]), 'hello', 'world')




(file #26625)

Ben Abbott <bpabbott>
Group Member
Mon 24 Sep 2012 10:43:20 PM UTC, comment #3: 

I fixed this in the development branch of Octave in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/1db706430c96).  You will need to build from Mercurial sources or wait until the next major release to see the fix.

Rik <rik5>
Group administrator
Fri 26 Aug 2011 10:09:51 PM UTC, comment #2: 

nice trick but it only seems to work for one legend entry, setting two fails in call to legend:

set(h1, 'DisplayName', 'legend key 1');
 set(h2, 'DisplayName', 'legend key 2');
 legend('right');


error: structure has no member `fontname'
error: evaluating argument list element number 1
error: called from:
error:   /usr/share/octave/3.4.0/m/plot/__go_draw_axes__.m at line 2086, column 3
error:   /usr/share/octave/3.4.0/m/plot/__go_draw_axes__.m at line 1475, column 31
error:   /usr/share/octave/3.4.0/m/plot/__go_draw_figure__.m at line 119, column 21
error:   /usr/share/octave/3.4.0/m/plot/__gnuplot_drawnow__.m at line 86, column 5

Anonymous
Sun 17 Jul 2011 03:52:37 AM UTC, comment #1: 

Confirmed.  And it happens with either gnuplot or the FLTK toolkit.

Rik <rik5>
Group administrator
Tue 12 Jul 2011 05:43:32 PM UTC, original submission:  

It's possible to specify the legend entry for a plot using the DisplayName property. However, if you use that method no legend is shown even when an explicit legend('show') is issued. The only solution I found to make the actual legend visible is to use legend('right'). This shows that the data specified using DisplayName is stored, it's just not evaluated when the plot is initially plotted nor on calling legend('show'). When the legend entry is specified using ';legend entry;' the legend is drawn upon plotting.

Example:


x = 0:pi/15:2*pi;
plot(x, sin(x), 'DisplayName', 'sin(x)')   % no legend
legend('show')    % doesn't work
legend('right')   % works
legend('hide')    % works
legend('show')    % works now

close all
clear all
x = 0:pi/15:2*pi;
plot(x, sin(x), ';sin(x);')   % works


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #26633:  matlab.pdf added by bpabbott (5KiB - application/pdf)
file #26634:  legend2.m added by bpabbott (39KiB - application/octet-stream)
file #26635:  test_legend.m added by bpabbott (361B - application/octet-stream)
file #26636:  legend2.pdf added by bpabbott (5KiB - application/pdf)
file #26625:  legend_show.pdf added by bpabbott (4KiB - application/pdf - plot (rand (3)); legend show)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bpabbott (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-09-25 bpabbott Attached File- Added matlab.pdf, #26633
        Attached File- Added legend2.m, #26634
        Attached File- Added test_legend.m, #26635
        Attached File- Added legend2.pdf, #26636
    2012-09-24 bpabbott Attached File- Added legend_show.pdf, #26625
    2012-09-24 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2011-07-17 rik5 CategoryPlotting with gnuplot Plotting
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code