bugGNU Octave - Bugs: bug #57685, legend misplaced when pbaspect()...

 
 

bug #57685: legend misplaced when pbaspect() used

Submitted by:  José Luis García Pallero <jgpallero>
Submitted on:  Tue 28 Jan 2020 05:26:01 PM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Ready For Test Assigned to:  None
Originator Name:  Open/Closed:  Open
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.

 

( Jump to the original submission)

Fri 07 Feb 2020 07:15:55 PM UTC, comment #10: 

Thanks, I pushed the patch here

http://hg.savannah.gnu.org/hgweb/octave/rev/9507b3cf5a86

Should we leave this report open ?

Pantxo Diribarne <pantxo>
Project Member
Mon 03 Feb 2020 04:59:30 PM UTC, comment #9: 

"Perfect is the enemy of good"

I think your patch improves the situation quite a bit and you should push it, even if there are odd corner cases still unresolved.

Rik <rik5>
Project Administrator
Sat 01 Feb 2020 12:43:56 PM UTC, comment #8: 

@Rik: By default your example from comment #7, works for me.
In order to reproduce, I used a larger aspect ratio ([5 1 1]), then I could see that the legend did not move after the xlabel is added.

There is already a listener on the tightinset property but it is not executed: as explained in comment #6, if the added xlabel fits in the "position box", the tightinset is unchanged (it is 0 before and after) ...

Pantxo Diribarne <pantxo>
Project Member
Fri 31 Jan 2020 10:57:16 PM UTC, comment #7: 

Much better.

I've got another piece of code which produces the wrong result.  In this case, instead of title() an xlabel is added after the legend object has been created.

clf
plot(rand(3));
legend('First','Second','Third');
## FIXME: Code works (legend re-positioned to be non-overlapping of xlabel)
##        IF pbaspect is commented out.
pbaspect ([2 1 1]);
hl = legend ();
set (hl, 'location', 'southoutside');
xlabel ({'line1', 'line2'});

Does there need to be a listener on tightinset or looseinset?

Rik <rik5>
Project Administrator
Thu 30 Jan 2020 09:11:45 PM UTC, comment #6: 

@Rik: The issue is that the axes tightinset margin is measured relative to the "position box", not to the "plot box".
I can't see any simple way to accurately know the extent of the box enclosing labels so I opted for temporarily switching the "plotboxaspectratiomode" to "auto". See attached updated patch.

(file #48307)

Pantxo Diribarne <pantxo>
Project Member
Wed 29 Jan 2020 09:00:42 PM UTC, comment #5: 

The patch works perfectly for the provided example.  However, there are other odd cases which don't work out.

plot (1:10)
title ({'1','2','3'})
legend ('abc', 'location', 'northoutside')
pbaspect ([2 1 1 ])

Before the patch, the legend is placed out of the way of the title text.  After the patch, the title and legend overlap.

File old_title.png

File new_title.png

(file #48302,

Rik <rik5>
Project Administrator
Wed 29 Jan 2020 05:22:26 PM UTC, comment #4: 

just tried the patch and can confirm that the legend stays pinned to the plot corner on resize via command or by mouse manipulation of the figure window

Nicholas Jankowski <nrjank>
Wed 29 Jan 2020 12:58:15 PM UTC, comment #3: 

The problem is that when the plotboxaspectration is modified, the "position" property does not reflect the actual position of the axes box. The attached patch seems to do the job.

(file #48301)

Pantxo Diribarne <pantxo>
Project Member
Tue 28 Jan 2020 06:56:24 PM UTC, comment #2: 

Good observation.  It may be that in Matlab the legend object is a hidden child of the axes object, rather than the figure object which is what Octave does.

Rik <rik5>
Project Administrator
Tue 28 Jan 2020 06:06:31 PM UTC, comment #1: 

as subsequently discussed on the maintainers list [1]

I can confirm this bug with Octave 5.1.0 in comparison to Matlab 2019a.  Two figures attached show output from Jose's script in both programs.  (output is the same on screen as in the generated png files)

The output is the same even if you change order of the pbaspect and legend commands.

Last, it appears that matlab pins the legend position to the plot, while octave pins it to the window.  resizing the window in matlab, the legend stays in the same place on the plot, even if the figure needs to be rescaled.  In octave, the legend moves around the plot to keep the same location in the figure window, and will move inside, outside, half-in-half-out, etc regardless of plot position or size.

[1] https://octave.1599824.n4.nabble.com/pbaspect-and-legend-tp4695458.html


Nicholas Jankowski <nrjank>
Tue 28 Jan 2020 05:26:01 PM UTC, original submission:  

I need to use the pbaspect() function in order to customize a figure aspect ratio. All works perfect except the legend, which is not maintained inside the plot box after the pbaspect() call. But in Matlab the legend is affected by the function. I think it is a bug in the Octave pbaspect(). The behavior is the same in Octave 5.1.0 and in the alpha 5.1.90 release (I suppose it is present in older versions too)

I'm using this script:

plot(rand(3));
legend('First','Second','Third');
pbaspect([2 1 1]);
print('check_pbaspect.png','-dpng');

José Luis García Pallero <jgpallero>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #48307:  bug57685.patch added by pantxo (5KiB - text/x-patch)
file #48302:  tst_pbaspect_title.m added by rik5 (97B - text/x-matlab)
file #48303:  new_title.png added by rik5 (13KiB - image/png)
file #48304:  old_title.png added by rik5 (11KiB - image/png)
file #48301:  legend_pbaspect.patch added by pantxo (5KiB - text/x-patch)
file #48295:  check_pbaspect_octave5.1.0.png added by nrjank (45KiB - image/png - pbaspect test images from octave and matlab)
file #48296:  check_pbaspect_matlab2019a.png added by nrjank (20KiB - image/png - pbaspect test images from octave and matlab)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Updated the item)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by nrjank (Updated the item)
  • -email is unavailable- added by jgpallero (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 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-02-07 pantxo StatusPatch Reviewed => Ready For Test
    2020-01-30 pantxo Attached File- => Added bug57685.patch, #48307
    2020-01-29 rik5 Attached File- => Added tst_pbaspect_title.m, #48302
        Attached File- => Added new_title.png, #48303
        Attached File- => Added old_title.png, #48304
        StatusPatch Submitted => Patch Reviewed
    2020-01-29 pantxo Attached File- => Added legend_pbaspect.patch, #48301
        StatusConfirmed => Patch Submitted
    2020-01-28 rik5 StatusNone => Confirmed
        Release5.1.90 => dev
        Summarypbaspect() and legend => legend misplaced when pbaspect() used
    2020-01-28 nrjank Attached File- => Added check_pbaspect_octave5.1.0.png, #48295
        Attached File- => Added check_pbaspect_matlab2019a.png, #48296

    Back to the top


    Powered by Savane 3.5