bugGNU Octave - Bugs: bug #55574, axis equal truncates upper and...

 
 

bug #55574: axis equal truncates upper and lower parts of picture

Submitter:  Philip Nienhuis <philipnienhuis>
Submitted:  Fri 25 Jan 2019 06:11:36 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Philip Nienhuis Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 02 Feb 2019 06:22:40 AM UTC, comment #7: 

Fixed on the development branch in this cset: https://hg.savannah.gnu.org/hgweb/octave/rev/a7dfb00d5bf5.

This will be a part of the Octave 6.1 release.  To access the fix sooner download axis.m from the Mercurial development branch and replace your local copy.

Closing report.

Rik <rik5>
Group administrator
Thu 31 Jan 2019 08:11:28 PM UTC, comment #6: 

As I brought it up I'll be glad to help testing and comparing with Matlab.

Philip Nienhuis <philipnienhuis>
Group Member
Thu 31 Jan 2019 07:42:39 PM UTC, comment #5: 

E-mail is a bad form for communicating nuance.  It's true it's not "wildly complicated" in an absolute sense, but I used the phrase to emphasize how unnecessarily complicated it is relative to what the code needs to do (just use set() for dataspectration and plotboxaspectratio).  I have a fix, but I need to do some testing.  This will definitely be going on the development branch so there is lots of time to test and find any problems.

Rik <rik5>
Group administrator
Thu 31 Jan 2019 06:37:23 PM UTC, comment #4: 

I already looked into this, but indeed it is not easily tractable (OTOH "wildly complicated" is a bit of an overstatement).
Yet I'm probably the first to stumble over it so that makes me cautious - it seems to have worked for many users over the years.

Philip Nienhuis <philipnienhuis>
Group Member
Thu 31 Jan 2019 06:29:40 PM UTC, comment #3: 

I think the axis.m script needs to be updated to rely more on the C++ graphics properties to do it's job.  According to Matlab, using 'axis equal' should do the following


Sets DataAspectRatio to [1 1 1], sets PlotBoxAspectRatio to [3 4 4], and sets the associated mode properties to manual. Disables the “stretch-to-fill” behavior.


The code in axis.m, however, is wildly complicated.


      elseif (strcmp (opt, "equal"))
        ## Get position of axis in pixels
        ca_units = get (ca, "units");
        set (ca, "units", "pixels");
        axis_pos = get (ca, "position");
        set (ca, "units", ca_units);

        pbar = get (ca, "plotboxaspectratio");
        dx = diff (__get_tight_lims__ (ca, "x"));
        dy = diff (__get_tight_lims__ (ca, "y"));
        dz = diff (__get_tight_lims__ (ca, "z"));
        new_pbar = [dx dy dz];
        new_pbar(new_pbar == 0) = 1;
        if (dx/pbar(1) < dy/pbar(2))
          set (ca, "xlimmode", "auto");
          new_pbar(1) = (dy / axis_pos(4)) * axis_pos(3);
        else
          set (ca, "ylimmode", "auto");
          new_pbar(2) = (dx / axis_pos(3)) * axis_pos(4);
        endif
        set (ca, "dataaspectratio", [1, 1, 1],
                 "plotboxaspectratio", new_pbar);


Changes should go on the development branch at this point.

Rik <rik5>
Group administrator
Fri 25 Jan 2019 09:16:00 PM UTC, comment #2: 

'axis equal ; axis tight' and 'axis image' work as you say, thanks.

it has to do this by shortening one of the axes because the original immage is 10x11


It looks like Octave has a default rectangular axis box setup that is not adapted synchronously with the axis units in case of "axis equal". Apparently Octave keeps arbitrarily the x-axis unchanged and adapts the y-axis but doesn't change the plot box, with clipping y-data as a result. Maybe changing the plot box aspect ratio and/or scale all axes so they fit in the plot box would be the expected action.

This hit me because I have Matlab code that does what I expect to happen (= no clipping). OTOH, with my data I may not have hit Matlab's default limits yet.

Philip Nienhuis <philipnienhuis>
Group Member
Fri 25 Jan 2019 06:35:37 PM UTC, comment #1: 

This issue keeps coming up in many different disguises.  The fundamental issue is that Octave clips (does not display) pixels in image objects which are outside the axes.  When 'axis equal' is issued it makes the linear distances of the X and Y axes equal, but it has to do this by shortening one of the axes because the original immage is 10x11.

Here is sample Octave session showing that.


octave:22> clf
octave:23> img = uint8 ([10: -1: 0] * 25)';
octave:24> size (img)
ans =

   11    1

octave:25> imshow (pic)
octave:26> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:27> axis equal
octave:28> axis
ans =

    0.50000   10.50000    2.05645    9.94355

octave:29> axis image
octave:30> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:31> diary off
octave:22> clf
octave:23> img = uint8 ([10: -1: 0] * 25)';
octave:24> size (img)
ans =

   11    1

octave:25> imshow (pic)
octave:26> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:27> axis equal
octave:28> axis
ans =

    0.50000   10.50000    2.05645    9.94355

octave:29> axis image
octave:30> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:31> diary off
octave:22> clf
octave:23> img = uint8 ([10: -1: 0] * 25)';
octave:24> size (img)
ans =

   11    1

octave:25> imshow (pic)
octave:26> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:27> axis equal
octave:28> axis
ans =

    0.50000   10.50000    2.05645    9.94355

octave:29> axis image
octave:30> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:31> diary off
octave:22> clf
octave:23> img = uint8 ([10: -1: 0] * 25)';
octave:24> size (img)
ans =

   11    1

octave:25> imshow (pic)
octave:26> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:27> axis equal
octave:28> axis
ans =

    0.50000   10.50000    2.05645    9.94355

octave:29> axis image
octave:30> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:31> diary off
octave:22> clf
octave:23> img = uint8 ([10: -1: 0] * 25)';
octave:24> size (img)
ans =

   11    1

octave:25> imshow (pic)
octave:26> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:27> axis equal
octave:28> axis
ans =

    0.50000   10.50000    2.05645    9.94355

octave:29> axis image
octave:30> axis
ans =

    0.50000   10.50000    0.50000   11.50000

octave:31> diary off


The quick solution is that you want 'axis image', i.e., "tight" + "equal" to properly display an image object.


Rik <rik5>
Group administrator
Fri 25 Jan 2019 06:11:36 PM UTC, original submission:  

(mentioned in / maybe related to bug #55514)

Steps to reproduce:

>> pic = repmat (uint8 ([10: -1: 0] * 25)', 1, 10);
>> imshow (pic)  ## Picture with 10 horizontal bands appears, good.
>> axis equal    ## Upper and lower bands have disappeared


I'd expect an almost square picture to keep its shape after "axis equal".
In Matlab r2019a prerelease this works, although the picture is very small.

This also happens with 4.4.1

Philip Nienhuis <philipnienhuis>
Group Member

 

(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 philipnienhuis (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-02 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2019-01-31 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code