bugGNU Octave - Bugs: bug #57881, Resizing subplot results in...

 
 

bug #57881: Resizing subplot results in disappearance of one of the plots

Submitted by:  Henk Borsje <hjborsje>
Submitted on:  Sat 22 Feb 2020 07:04:13 PM UTC  
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  hjborsje Open/Closed:  Closed
Release:  6.0.90 Operating System:  Any

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 27 Mar 2020 02:29:01 PM UTC, comment #7: 

I pushed the following change for the doc string of subplot:
https://hg.savannah.gnu.org/hgweb/octave/rev/bc829338e353

Closing as fixed.

Any improvements to the wording or clarification suggestions are always welcome.

Markus Mützel <mmuetzel>
Project Member
Thu 26 Mar 2020 10:33:21 AM UTC, comment #6: 

Thanks for your clarification. The notation in the function header of subplot.m wasn't clear to me. This does indeed what I want without unnecessary steps. Putting a 'refresh()' after each plot is useful. The ML documentation is indeed very clear about subplot.

It also says:

To overlay axes, use the axes command instead. The subplot function deletes existing axes that overlap new axes. For example, subplot('Position',[.35 .35 .3 .3]) deletes any underlying axes, but axes('Position',[.35 .35 .3 .3]) positions new axes in the middle of the figure without deleting underlying axes.

Henk Borsje <hjborsje>
Thu 26 Mar 2020 07:44:14 AM UTC, comment #5: 

Looking at the input validation of "subplot", the "rows, cols, index" triplet and the "position" property-value-pair seem to be mutually exclusive. (The triplet takes precedence in this case.)
This also is what the Matlab documentation of that function suggests. [1]

With this modified code snippet, the layout looks like you probably expect for me:

figure (1); clf (1)
m = 8;
pos = [ 0.07, 0, 0.92, 0.5/m];
for i = 1:m
  pos(2) = 0.95 - i * 0.91/m;
  h(i) = subplot ('position', pos);
endfor
title(h(1), 'My title')

Can you help improve the documentation of subplot to clarify this issue?

[1]: https://de.mathworks.com/help/matlab/ref/subplot.html

Markus Mützel <mmuetzel>
Project Member
Wed 25 Mar 2020 09:25:42 PM UTC, comment #4: 

I was only using a loop so that I could check the response of the plot to a resize of the figure window. My only concern is getting the proper layout of the subplots, also after resizing, and at the same time reducing the wasted space with any number of subplots (in a single column). The following code does a consistent good layout for me:
It still is necessary to change the position with a separate call to 'set', while it should be possible in a single call to subplot. I looked at the code subplot.m and something seems wrong when 'position' is given. 
%%%%%%%%%%% begin code %%%%%%%%%%%%%%%%%
rnge = 0.5:99.5;
figure (1)
m = 9;    % The number of subplots
pos = [ 0.05, 0, 0.93, 0.88/m];

d = rand(100,m);
for i = 1:m
pos(2) = 0.96 - i * 0.90/m;
h = subplot(m,1,i,'position',pos); % position is ignored
plot(rnge,d(:,i))
set (h,'position',pos);
if i == m
    axis("label")
else
      axis("labely")
endif
grid,ylabel(sprintf('Series %d',i));
if i == 1
    title(sprintf('Showing %d subplots',m))
endif
endfor
%%%%%%%%%%%% end of code %%%%%%%%%

comment #3:

> I can reproduce your issue.
>
> Is there a specific reason, why you don't create the axes layout only once and store the axes handles?
> Subsequent loops could just update those axes instead of recreating them. That should also boost performance of your code.
>
> "subplot" seems to have a hard time identifying the repositioned axes on sub-sequent loops.

Henk Borsje <hjborsje>
Wed 25 Mar 2020 06:08:08 PM UTC, comment #3: 

I can reproduce your issue.

Is there a specific reason, why you don't create the axes layout only once and store the axes handles?
Subsequent loops could just update those axes instead of recreating them. That should also boost performance of your code.

"subplot" seems to have a hard time identifying the repositioned axes on sub-sequent loops.

Markus Mützel <mmuetzel>
Project Member
Tue 17 Mar 2020 03:17:49 PM UTC, comment #2: 

I seem to be beating a dead horse, but there still are inconsistencies in the subplot function that causes me problems.
According to doc, it should be possible to use the command:

subplot (m,n1,n2,'position',[p1 p2 p3 p4])

But the provided position is not used.  Stepping through the code shows indeed that both position and outerposition are recalculated.

Henk Borsje <hjborsje>
Sun 23 Feb 2020 05:39:49 PM UTC, comment #1: 

The same problem appears when I change the default figure size in the startup.m file:

set (0,'defaultfigureposition',[20,60,800,700])

Henk Borsje <hjborsje>
Sat 22 Feb 2020 07:04:13 PM UTC, original submission:  

When I resize Figure 1 during execution of the following code one or two of the subplots completely disappear. My result is shown in the attached file Subplot8.jpg
============================================= Begin code ======
m = 8;
rnge = 0.5:9.5;
figure (1)
pos = [ 0.07, 0, 0.92, 0.5/m];

for k = 1:4
d = rand(10,m);
%clf;
for i = 1:m
pos(2) = 0.95 - i * 0.91/m;
h = subplot(m,1,i);
plot(rnge,d(:,i))
set (h,'position',pos);
if i == m
axis("label")
else
axis("labely")
endif
grid,ylabel(sprintf('Series %d',i));
if i == 1
title('My title')
endif
endfor
pause(2)
endfor
============================= End code ==================

Henk Borsje <hjborsje>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #48530:  Screenshot@2020-03-02@at@4.20.47@PM.png added by the_brainiac (286KiB - image/png - So , I ran the given code in MacOSX and the result came out perfectly fine. I've attached it above. I think this bug is only limited to Windows.)
file #48474:  Subplot8.jpg added by hjborsje (93KiB - image/jpeg)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by the_brainiac (Updated the item)
  • -email is unavailable- added by hjborsje (Submitted the item)
  • -email is unavailable- added by hjborsje
  •  

    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
    2020-03-27 mmuetzel StatusConfirmed => Fixed
        Open/ClosedOpen => Closed
    2020-03-26 mmuetzel CategoryPlotting => Documentation
        Releasedev => 6.0.90
    2020-03-25 mmuetzel StatusNone => Confirmed
        Release5.2.0 => dev
        Operating SystemMicrosoft Windows => Any
    2020-03-02 the_brainiac Attached File- => Added Screenshot@2020-03-02@at@4.20.47@PM.png, #48530
    2020-02-22 hjborsje Attached File- => Added Subplot8.jpg, #48474
        Carbon-Copy- => Added henk.borsje@gmail.com

    Back to the top


    Powered by Savane 3.5