bugGNU Octave - Bugs: bug #49494, rescaling axes does not modify...

 
 

bug #49494: rescaling axes does not modify gca.ylim

Submitter:  Clinton Winant <cwinant>
Submitted:  Mon 31 Oct 2016 08:01:05 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Clinton Winant Open/Closed:  * Open
Release:  * 4.2.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 28 Aug 2017 06:34:14 PM UTC, comment #6: 

Posted to the mailing list, not the tracker:

I confirm that with the change from 4.2.0 to 4.2.1 drawnow no longer
"fixes" the problem.  To be sure we are all on the same page, the OP was to
point out that in this case, when a rescale occurs because of a forced
change in ytickmode, the ylimits in gca are not updated.  I think they
ought to be, or at least there needs to be a way (as in 4.2.0 with drawnow)
to force refreshing values in gca, otherwise locating text after the
rescale is unreliable.   Unfortunately I do not have easy access to matlab,
or I would be able to report how the same script works there.

I would very much like to help this effort (and octave in general).  Please
let me know how I can support you.

This may be a good place to thank developers for all the additions to
4.2.1, notable rhe new availability of opengl through ssh tunneling.  Way
to go!

John W. Eaton <jwe>
Group administrator
Tue 07 Mar 2017 03:52:44 PM UTC, comment #5: 

I am not sure why inserting "drawnow" helped in that specific RC. It no longer changes anything for me, too. Sorry that I gave wrong information. I was under the impression that "drawnow" would trigger an update of all graphics properties.

I also tried in Windows and got the same result as the OP.

The example in comment #0 works if either "ytick" or "ytickmode" is set before the last call of "plot". So maybe both should update the axis limits when changed. I can provide a changeset if this is the case.
Do we really want that the axes limits change in that case? Or is that the bug?

I had to slightly modify your script so that it could run in Matlab:

>> figure;
plot([0 1],[-2.02 1.3311],'k','linewidth',2);
yl = get (gca, 'ylim')
set(gca,'ytickmode','manual')
yl = get (gca, 'ylim')
text(.1,.5,num2str(yl(1),'%3.1f'))
yl = get (gca, 'ylim')

yl =

   -2.5000    1.5000


yl =

   -2.5000    1.5000


yl =

   -2.5000    1.5000


I get the same results when I execute the script line by line.

Markus Mützel <mmuetzel>
Group administrator
Sun 05 Mar 2017 09:12:12 PM UTC, comment #4: 

Drawnow has no effect for me and I am pretty sure that it should not be necessary here, I don't know that an axes object has to be rendered (that is what drawnow forces) for its properties to be right (for ui* objects it is another matter).
Further more I see the reported behavior wether I run the code as a script or paste it in the command window. In the latter situation Octave returns after each command and it should be equivalent to calling drawnow.

What I see here is that changing the "ytickmode" property doesn't force limits to be updated. Octave needs another object to be added (here the text object) to have the axes limits recomputed.
What does Matlab do/return executing the script below?


plot([0 1],[-2.02 1.3311],'k','linewidth',2);
yl = get (gca, 'ylim')
set(gca,'ytickmode','manual')
yl = get (gca, 'ylim')
text(.1,.5,num2str(sgca.ylim(1),"%3.1f"))
yl = get (gca, 'ylim')



Pantxo Diribarne <pantxo>
Group Member
Mon 07 Nov 2016 09:41:47 AM UTC, comment #3: 

I wouldn't consider this a workaround but the proper way to do it.
AFAIU, Octave (and Matlab) buffers commands that change graphics settings and executes them all at once when it deems it necessary or when the user calls drawnow. This is probably done to improve performance instead of calling all the necessary update function after each change of any property.

That said, you don't have to call "drawnow" everytime after you changed the graphics properties. Octave will update the properties when it deems it necessary.
However, you should always call "drawnow" (or a function that calls "drawnow" such as "pause") before getting properties of graphics if you expect to get updated values.

Markus Mützel <mmuetzel>
Group administrator
Sat 05 Nov 2016 06:11:03 PM UTC, comment #2: 

Using drawnow is a good workaround (works for me in 4.2.0-rc3), but I don't understand the logic?  Surely any call to set(gca,..) ought to update all gca properties, particularly if that call changes those properties?

An example of how illogical this is is to include a pause statement before the sgca=get(gca) command (but no drawnow).  In that case the program works correctly (since pause forced drawnow), and we have a program that behaves differently, depending on whether there is a pause or not!!

Is the current rule that drawnow should be called anytime the current axes properties are modified?

Clinton Winant <cwinant>
Sat 05 Nov 2016 01:37:40 PM UTC, comment #1: 

You are missing a "drawnow" before line 15 of your script to make sure you are getting the updated axis limits.

This did not help for me in 4.0.3. But with that command added, it works as expected in Octave 4.2.0-rc3.

Markus Mützel <mmuetzel>
Group administrator
Mon 31 Oct 2016 08:01:05 PM UTC, original submission:  

The enclosed script plots a straight line twice.  Both the script and resulting figure are attached. In the right hand plot, the y-axis tick mode has been set to manual.  Since the right and left plots are not the same, I conclude that the y-axis has been rescaled by the set(gca... call.  However a subsequent call to gca shows that ylim is the same for both plots.  As a result the line "rescale" is placed correctly in only the left hand plot.
Ubuntu 16.04  gl2ps 1.3.8

GNU Octave, version 4.2.0-rc2
Copyright (C) 2016 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type 'warranty'.

Octave was configured for "x86_64-pc-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

>> subplot(1,2,1)
>> plot([0 1],[-2.02 1.3311],'k','linewidth',2);hold on
>> plot([0 1],[0 0],'k')
>> %%      set(gca,'ytickmode','manual','ytick',[]);
>> sgca=get(gca);
>> text(.1,.5,num2str(sgca.ylim(1),"%3.1f"))
>> text(.3,.5,num2str(sgca.ylim(2),"%3.1f"))
>> text(0.1,sgca.ylim(1),'rescale')
>> %% plot the same thing, but force rescale by turning
>> %% ytickmode to manual
>> subplot(1,2,2)
>> plot([0 1],[-2.02 1.3311],'k','linewidth',2);hold on
>> plot([0 1],[0 0],'k')
>> set(gca,'ytickmode','manual','ytick',[]);
>> sgca=get(gca);
>> text(.1,.5,num2str(sgca.ylim(1),"%3.1f"))
>> text(.3,.5,num2str(sgca.ylim(2),"%3.1f"))
>> text(0.1,sgca.ylim(1),'rescale')


Clinton Winant <cwinant>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #38848:  debug_rescale.m added by cwinant (612B - text/x-objcsrc)
file #38849:  debug_rescale.eps added by cwinant (8KiB - image/x-eps)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by cwinant (Submitted the item)
  • -email is unavailable- added by cwinant
  •  

    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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-26 mtmiller Carbon-CopyRemoved 80942 -
    2017-03-07 mmuetzel Release4.2.0 4.2.1
        Operating SystemGNU/Linux Any
    2016-11-17 mtmiller Release4.2.0-rc2 4.2.0
    2016-10-31 cwinant Attached File- Added debug_rescale.m, #38848
        Attached File- Added debug_rescale.eps, #38849
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code