bugGNU Octave - Bugs: bug #56972, Calling again command 'legend'...


bug #56972: Calling again command 'legend' after figure window resize is messing plot layout

Submitted by:  Valdas <zmogas>
Submitted on:  Mon 30 Sep 2019 06:51:24 PM UTC  
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 18 Nov 2019 08:51:21 PM UTC, comment #4: 

Verified with new legend.m.  Marking as fixed and closing report.

Rik <rik5>
Project Administrator
Mon 18 Nov 2019 09:48:26 AM UTC, comment #3: 

legend.m has been rewritten (for OpenGL toolkits only). This bug should now be fixed.

Marking ready for test.

Pantxo Diribarne <pantxo>
Project Member
Tue 01 Oct 2019 03:06:55 PM UTC, comment #2: 

 I agree that workflow you mentioned is OK, but it is for "one shot“: plot then print or analyze.
 In situations where you must change legend's content multiple times (f.e. interactive data analysis application which I'm developing) I found only way to change legend's content is to call 'legend' again (hence I found this bug).

Valdas <zmogas>
Tue 01 Oct 2019 02:32:53 PM UTC, comment #1: 

I know it isn't perfect, but as a workaround, add the legend as the last item to a plot.

For Octave, this workflow is best

1) Do calculations
2) Plot data
3) Style the plot with xlabel, ylabel, title, text, etc.
4) Finally, add legend.

It usually isn't a problem to do things in this order, and it will work in either Matlab or Octave.

Rik <rik5>
Project Administrator
Mon 30 Sep 2019 06:51:24 PM UTC, original submission:  

 First case:
- call this command (result in fig_1.png):

close all; x=[-pi:0.1:pi]; h_p=plot(x,sin(x),x,cos(x)); h_l=legend([h_p(1),h_p(2)],{'sinusas','kosinusas'},'location', 'northoutside','Orientation','horizontal');

- then shrink figure vertically (result in fig_2.png);
- call 'legend' again: 


 Result (fig_3.png) was mess in plot layout. Seems that legend was placed in position (in pixels?) when figure was in original size, and then axes follows legend and expands vertically.

 Second case:
- execute this command (result in fig_4.png):

close all; x=[-pi:0.1:pi]; h_p=plot(x,sin(x),x,cos(x)); h_l=legend([h_p(1),h_p(2)],{'sinusas','kosinusas'});

- then expand figure vertically (result in fig_5.png);
- call 'legend' again: 


 Result in fig_6.png: legend jumps in to middle of plot window (original absolute position of canvas in pixels?).

Operating System: Kubuntu 19.04
KDE Plasma Version: 5.16.5
KDE Frameworks Version: 5.62.0
Qt Version: 5.12.2
Kernel Version: 5.0.0-29-generic
OS Type: 64-bit
Processors: 16 × AMD Ryzen 7 1700X Eight-Core Processor
Memory: 15,7 GiB

version 6.0.0
graphics_toolkit = qt
hg summary:
parent: 27439:251056aeba5d tip
 Align negative numbers correctly with g format (bug #56940).
branch: default
bookmarks: *@
commit: 2222 unknown (clean)
update: (current)

Valdas <zmogas>


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

Attach Files:

Attached Files
file #47599:  fig_5.png added by zmogas (45KiB - image/png)
file #47600:  fig_6.png added by zmogas (43KiB - image/png)
file #47595:  fig_1.png added by zmogas (38KiB - image/png)
file #47596:  fig_3.png added by zmogas (26KiB - image/png)
file #47597:  fig_2.png added by zmogas (28KiB - image/png)
file #47598:  fig_4.png added by zmogas (38KiB - image/png)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by zmogas (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-11-18 rik5 StatusReady For Test => Fixed
        Open/ClosedOpen => Closed
    2019-11-18 pantxo StatusConfirmed => Ready For Test
    2019-10-01 rik5 StatusNone => Confirmed
    2019-09-30 zmogas Attached File- => Added fig_5.png, #47599
        Attached File- => Added fig_6.png, #47600
    2019-09-30 zmogas Attached File- => Added fig_1.png, #47595
        Attached File- => Added fig_3.png, #47596
        Attached File- => Added fig_2.png, #47597
        Attached File- => Added fig_4.png, #47598

    Back to the top

    Powered by Savane 3.5