bugGNU Octave - Bugs: bug #42034, legend () call should not create...

 
 

bug #42034: legend () call should not create legend in some cases

Submitter:  sergey plotnikov <nul0m>
Submitted:  Thu 03 Apr 2014 08:50:15 AM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 07 May 2014 02:58:46 AM UTC, comment #7: 

It should be all fixed up in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/adb948d7fae4).  Closing report.

Rik <rik5>
Group administrator
Tue 06 May 2014 05:47:03 PM UTC, comment #6: 

yes, it's []. here is the output:


hl = plot (1:10);
set (hl, 'displayname', 'TestText');
hleg = legend ()

hleg =

     []


sergey plotnikov <nul0m>
Tue 06 May 2014 04:25:59 PM UTC, comment #5: 

@ssergey: Could you run one more test.  I want to know how legend behaves when it is called without arguments, but the DisplayName property is set.


hl = plot (1:10);
set (hl, 'displayname', 'TestText');
hleg = legend ()


Is hleg still [] for this call?

Rik <rik5>
Group administrator
Sun 13 Apr 2014 04:04:04 PM UTC, comment #4: 

Thanks for the extra testing.  We now know, at least, what behavior Octave should be trying to mimic.  I've marked the bug as confirmed.

Rik <rik5>
Group administrator
Fri 04 Apr 2014 08:44:23 AM UTC, comment #3: 

Sorry, I should have provided more details on how I thought.

  1. My assumption was that legend () is identical to legend (gca), which is not stated explicitly in the documentation, but is quite logical.
  2. It was also logical to me (according to the quote I posted) that the empty legend_handle as an output of legend (...) command may appear only if legend was not created during that call.
  3. Assuming there's a possibility of creating no legend during a call of legend (...) I tried to come up with a proper inputs (instead of dots) which could cause such a behavior.
  4. legend (<labels>) as well as legend ("show") or legend ("toggle") must create some legend for sure (confirmed)
  5. so the list of possible commands (I guessed) was


lh = legend ("hide");
lh = legend ("boxon");
lh = legend ("boxoff");
lh = legend ("off");
lh = legend (); % as a simplest possible case
lh = legend ("location","northeast");
lh = legend ("orientation","vertical");


Being tested in Matlab just last two commands created a legend with default set of labels ("data1", "data2", ...), all the other displayed no legend and returned [].

@Rik:
So, the first case resulted in hl = [] and no legend displayed and the second one created legend with default labels.

sergey plotnikov <nul0m>
Thu 03 Apr 2014 11:11:42 PM UTC, comment #2: 

I agree with Mike that it is unclear what legend() is supposed to do in this case.  If you read the documentation for legend it says that when no label is supplied it should create a label using the sequence "data1", "data2", ...

Can someone try the following example in Matlab


plot (rand (3,3))
hl = legend ()


Octave seems to do the correct thing here in that it builds a legend object with 3 labels (data1, data2, data3), and then returns the handle.  However, maybe you are supposed to do


plot (rand (3,3))
hl = legend ('show')


if you want to use default labels on a plot that doesn't have a legend.

Rik <rik5>
Group administrator
Thu 03 Apr 2014 07:37:55 PM UTC, comment #1: 

I agree with your quote from the Matlab documentation, but it doesn't actually say anywhere on that documentation that calling legend with no arguments is allowed or what it should do. If it does say so and I missed it, please point it out because it's not very clear.

The following example is documented and does work in Octave:


close all;
plot (1:10, sin (1:10));
legh = legend ('off');
isempty (legh)


Mike Miller <mtmiller>
Group Member
Thu 03 Apr 2014 08:50:15 AM UTC, original submission:  

The following case should return [] and not create any legend.


close all;
plot (1:10,sin(1:10));
legh = legend ();
isempty (legh)


According to this, "legend_handle = legend(...) returns the handle to the legend on the current axes, or [] if no legend exists."

I can confirm that in Matlab it holds for any number of output arguments.

sergey plotnikov <nul0m>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by nul0m (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-05-07 rik5 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2014-05-06 rik5 StatusConfirmed In Progress
    2014-04-13 rik5 StatusNeed Info Confirmed
    2014-04-03 mtmiller StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code