bugGNU Octave - Bugs: bug #64907, Add support for function...

 
 

bug #64907: Add support for function `tightPosition`

Submitter:  Liang Tang <lt1234>
Submitted:  Sun 19 Nov 2023 06:57:05 PM UTC
   
 
Category:  Plotting with OpenGL Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  In Progress Assigned to:  None
Originator Name:  lt1234 Open/Closed:  * Open
Release:  * 8.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 23 Nov 2023 02:00:05 PM UTC, comment #13: 


@pantxo,

I would be honest here.  I don't agree to this compatibility.  For example, to get 4, we can do (5-1), (2+2), etc.  If matlab chooses (2+2), I really don't mind to follow because the end result is 4, which is the priority.  The returned value from axes position at the presence of active axis square is incorrect.  From my view point, we are agreeing to 10=(2+2).   But, let me not continue on this.  You may have other demands to meet. 

I don't have any understanding of the interaction of Octave plotting codes.  So, I don't know if other plotting features may result in the same observation as we have seen from axis square.  I also don't know why axes property value must be different than what tightposition outputs. If the valid reason is for software internal and cannot be hidden from the users, you should have the say for what to do. 

From some trials, I do see that the axis properties like equal, square are mutually exclusive.  But the current documentation does not indicate so. For example, it is very clear why the linear and log scale must be mutually exclusive.  But it is unclear (to me) why equal and square need to be mutually exclusive.  I agreed in the prior comments not to look into this.    So, this reply is specific to square only. Prior to when I stopped trial runs, only the combination of square and position showed differences.  My trials are not meant to be a "complete testing".  

This is my proposal:  add a short paragraph after the current documentation. Doing it this way shifts the burden to the users.   English is never one of my strengths.  Feel free to change/remove as you want.   I am not in the position to fill in the right words for the "????" below. 

Thanks,
 
position: four-element vector, def. [0.1300 0.1100 0.7750 0.8150]
Specify the position of the plot excluding titles, axes, and legend. The four elements of the vector are the
coordinates of the lower left corner and width and height of the plot, in units normalized to the width and
height of the plot window. For example, [0.2, 0.3, 0.4, 0.5] sets the lower left corner of the
axes at (0.2, 0.3) and the width and height to be 0.4 and 0.5 respectively. See outerposition property.

When axis square immediately precedes the axes position inquiry, position returns ????. ????? may be utilized to obtain
the actual plot window coordinates.

Liang Tang <lt1234>
Thu 23 Nov 2023 10:28:52 AM UTC, comment #12: 

@lt1234: Proposition (1) is not acceptable since Octave strives at being as much ML compatible as possible. The "position" property being the root of the axes layout, this would be a major inconsistency and would lead to figures being very different when created in one or the other environment. So actually, in comment #8, I was asking for some help in rewording the documentation to make it clear that "position" doesn't always represent the actual axes layout (proposition (2)).

Pantxo Diribarne <pantxo>
Group Member
Tue 21 Nov 2023 10:29:09 PM UTC, comment #11: 

@pantxo,

With your recommendation, I will repeat my prior email: The m file you attached works and it outputs the numbers that I was expecting, originally, to have from "position".

For the ambiguous items, I will leave them open and not address them here.

In comment #8, you had: As for the documentation not being correct, can you suggest rewording that would make things more clear?

This all comes down to the occurrences of axes "property" deviating  from the documentation.  I think we know one exception.  But I don't know if there are other unknowns.  Two possible ways I had in mind:

(1) Deviate from matlab for the one instance we know. 
(2) Add note to the documentation for the effect of axis square on the axis property and how to obtain the correct value.

As a user, I prefer (1). (1) and the documentation are consistent.   Thanks.

Liang Tang <lt1234>
Tue 21 Nov 2023 06:17:44 PM UTC, comment #10: 

@lt1234: Please keep your observations focused on the main topic of this feature request. Anything outside the construction/testing of the  `tightPosition` function should be discussed either in another bug report or on discourse if you are not sure what you observe is a bug.

Pantxo Diribarne <pantxo>
Group Member
Tue 21 Nov 2023 05:37:24 PM UTC, comment #9: 

@pantxo,

Thanks.  The m file you attached works and it outputs the numbers that I was expecting, originally, to have from "position".  Just in case this log is used later, the "axes square" in comment #8 should be axis square. 

During my trial, I have some observations that may be what the software meant to do but I was not ready for.  Two (or may be others that I don't know) axis properties seem to be mutually exclusive.  The example below demonstrates what I had seen.  If this is what is supposed to, there is nothing I am requesting to change.  Seemingly xlim and ylim must be used to get a meaningful display involves physical dimensions. 

cen=[1 2]'; xx=[4 1]'; rad=2;
fid=figure('name', '3'); axs(3)=axes(fid, 'position', [0.1 0.1 0.8 0.8]); axis square;grid on; % axis equal;
h=viscircles(cen',rad); hold on;
% break the (implicit) equal axis from the circle and square   
g=plot(xx(1), xx(2), 'o'); set(g, 'markerfacecolor', get(g, 'color')); 
% try to fix the axis spacing and somehow break the axis square
axis equal  % axis square not honored !
% try to fix the axis aspect ratio and somehow break the axis equal 
axis square  % axis equal is not honored

Liang Tang <lt1234>
Tue 21 Nov 2023 08:44:21 AM UTC, comment #8: 

@lt1234: You can download the function file from comment #6 and use it as such:


plot (1:10);
xlabel xlabel
ylabel ylabel
title title

axes square
pos = tightPosition (gca);
annotation("rectangle", pos,"Color", "g" ,"LineWidth", 2)
pos = tightPosition (gca, 1);
annotation("rectangle", pos,"Color", "b" ,"LineWidth", 2)


As for the documentation not being correct, can you suggest rewording that would make things more clear?

Pantxo Diribarne <pantxo>
Group Member
Mon 20 Nov 2023 06:40:04 PM UTC, comment #7: 


Thanks.

I don't know how to utilize the info in comment # 5. 

Not knowing what comments #5 means, I have a question. 

When the [x0 y0] from axis position properties does not update when the displayed plot area [x0 y0] in the figure window had been moved, do you have a recommendation how to work with a function like annotation, which bases on the figure coordinate system to define the x y pair?  Is there other data in Octave that provides the blue box, shown in the link, relative to the figure coordinate system? 

For the simple example I had, Octave and matlab results are the same.  From my view point, the results are inconsistent with software documentation. 

Thanks again.

Liang Tang <lt1234>
Mon 20 Nov 2023 06:20:50 PM UTC, comment #6: 

Here is a preliminary tentative implementation for testing. AFAICS it works for 2D figures, not that great for 3D.

(file #55342)

Pantxo Diribarne <pantxo>
Group Member
Mon 20 Nov 2023 08:41:55 AM UTC, comment #5: 

The legend function has a sub function called "boxposition" to do that job.

Pantxo Diribarne <pantxo>
Group Member
Mon 20 Nov 2023 08:36:45 AM UTC, comment #4: 

@Pantxo: No worries. Resetting the tags and title.

Markus Mützel <mmuetzel>
Group administrator
Mon 20 Nov 2023 08:11:03 AM UTC, comment #3: 

@Markus: sorry our responses crossed. Fill free to redo all the changes you had done (I can't since OI did not see them).

Pantxo Diribarne <pantxo>
Group Member
Mon 20 Nov 2023 08:08:17 AM UTC, comment #2: 

This behaviour, even though it is surprising, I admit, is compatible with ML (try your code in ML and you'll obtain the same result). The "position" property defines the area out of which the plot cannot be. By default the axes actual position coincides with the `position` property, but if you prescribe the plotboxaspectratio (as you do using `axis square`) Octave rescales the axes to honor this aspect ratio while still fitting in the box defined by the "position" property. HTH

Closing report as invalid.

Pantxo Diribarne <pantxo>
Group Member
Mon 20 Nov 2023 08:03:53 AM UTC, comment #1: 

The behavior you are describing is expected and compatible to Matlab's behavior. See: https://www.mathworks.com/help/matlab/creating_plots/automatic-axes-resize.html

IIUC, you'd like to get the results that the Matlab function `tightPosition` would likely return. Afaict, that function hasn't been implemented for Octave yet though.
I'm converting this report to a feature request for that function. Contributions are welcome.

Markus Mützel <mmuetzel>
Group administrator
Sun 19 Nov 2023 06:57:05 PM UTC, original submission:  

From matlab on-line document, axes 'position' property provides the specifications of the plot area, i.e., [x0 y0 width height].  See "Control Axes Layout". 

The following example shows Octave axes position, same definition, may not update when plot area is changed.  The example shows that the two figures are the same in dimension but with two different plot areas.  But [x0 y0] are identical which is not what I had expected.   x0 must be different viewing the displayed figures/axes, see attached zip files. 

Any user's calculation based on [x0 y0] would be invalid. 

Thanks. 

figure;
h=plot([0 1], [0 1]); display(get(gca, 'position')); 
hgsave('rectangle.ofig')
axis square; drawnow;  display(get(gca, 'position'));
hgsave('square.ofig')

>> figure;
>> h=plot([0 1], [0 1]); display(get(gca, 'position'));

   0.1300   0.1100   0.7750   0.8150

>> hgsave('rectangle.ofig')
>> axis square; drawnow;  display(get(gca, 'position'));

   0.1300   0.1100   0.7750   0.8150

>> hgsave('square.ofig')
>>


Liang Tang <lt1234>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #55342:  tightPosition.m added by pantxo (3KiB - text/x-objcsrc)
file #55340:  rectangle_square.zip added by lt1234 (11KiB - application/x-zip-compressed)

 

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 mmuetzel (Posted a comment)
  • -email is unavailable- added by lt1234 (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 25 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-11-20 pantxo Attached File- Added tightPosition.m, #55342
        StatusInvalid / Not an Octave Bug In Progress
    2023-11-20 pantxo Operating SystemMicrosoft Windows Any
    2023-11-20 pantxo Severity1 - Wish 3 - Normal
        Priority3 - Low 5 - Normal
        Item GroupFeature Request Incorrect Result
        StatusConfirmed Invalid / Not an Octave Bug
        Operating SystemAny Microsoft Windows
    2023-11-20 mmuetzel Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low
        Item GroupIncorrect Result Feature Request
        StatusInvalid / Not an Octave Bug Confirmed
        Operating SystemMicrosoft Windows Any
        SummaryAxes position property Add support for function `tightPosition`
    2023-11-20 pantxo Open/ClosedClosed Open
    2023-11-20 pantxo CategoryPlotting Plotting with OpenGL
        Severity1 - Wish 3 - Normal
        Priority3 - Low 5 - Normal
        Item GroupFeature Request Incorrect Result
        StatusConfirmed Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
        Operating SystemAny Microsoft Windows
        SummaryAdd support for function `tightPosition` Axes position property
    2023-11-20 mmuetzel Severity3 - Normal 1 - Wish
        Priority5 - Normal 3 - Low

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code