bugGNU Octave - Bugs: bug #58566, plotyy() and subplot() generate...

 
 

bug #58566: plotyy() and subplot() generate errors

Submitted by:  Neil Konzen <waterdog1>
Submitted on:  Sun 14 Jun 2020 12:15:03 PM UTC  
 
Category:  Documentation Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error
Status:  Confirmed Assigned to:  None
Originator Name:  waterdog1 Open/Closed:  Open
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)

Mon 15 Jun 2020 03:15:20 PM UTC, comment #10: 

We had issues where subplot had a hard time to recognize that it should re-use (instead of replace) an axes several times before (e.g. after adding legends, moving the position slightly, adding decorations, colorbars, ...).
So I'd recommend to create the subplot axes only once generally (not only for plotyy).
But if you think it is necessary, we could add another comment in the docstring for plotyy.

I didn't yet completely understand the issue with "hold on". But it looks like it is something different.
Please open a new report about the issue with "hold on".

I'll recategorize this one to a documentation bug.

Markus Mützel <mmuetzel>
Project Member
Mon 15 Jun 2020 02:24:03 PM UTC, comment #9: 

You can replace plotyy.m (in octave\5.2.0\plot\draw\ ) with
the one that I attached in comment 2.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 15 Jun 2020 02:07:50 PM UTC, comment #8: 

I uninstalled and reinstalled my Octave from octave-5.2.0_1-w64-installer and continue to get those errors with the original script I posted.  Returning here, I see Dmitri is seeing the problem too.

It turns out the documentation for Matlab plotyy actually documents the fact that "the secondary axis will be ignored" if it is called with the array of axes returned by a previous call to plotyy. They also recommend using yyaxis() instead, which is in fact the nice way to do it.  But that's a recent function not yet implemented in Octave.

Markus, your workarounds work fine for me, on Octave and Matlab.  I am now trying them out in my real code.  Your suggestion to amend the docs is a great idea.  But I suggest the changes should be to the docstring of plotyy, since that is where people go to plot on two y axes.

The "hold on" problem is something I noticed searching for a workaround -- that issue seems pretty serious to me, and worth a bug report, especially as it doesn't seem related to dual-Y-axis plotting.  Shall I submit a separate bug, or will one of you follow up?

Neil Konzen <waterdog1>
Mon 15 Jun 2020 01:06:23 PM UTC, comment #7: 

So maybe we should just document that that is the supported way of using "subplot" with "plotyy" in a loop.
Maybe a "usage recommendation" at the end of the docstring of subplot. Something in the lines of:
If subplot axes should be referenced repeatedly, consider creating and storing their axes handles beforehand instead of calling subplot repeatedly for the same axes.
Example:

  x = 1:10;
  y = rand (16, 10);
  for i_plot = 1:4
    hax(i_plot ) = subplot (2, 2, i_plot );
    hold (hax(i_plot ), "on");
    grid (hax(i_plot ), "on");
  endfor
  for i_loop = 1:2
    for i_plot =1:4
      iy = (i_loop -1)*4 + i_plot;
      plotyy (hax(i_plot), x,y(iy,:), x,y(iy+1,:));
    endfor
  endfor

Markus Mützel <mmuetzel>
Project Member
Mon 15 Jun 2020 10:51:42 AM UTC, comment #6: 

Markus, your script works for me.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 15 Jun 2020 10:03:29 AM UTC, comment #5: 

The one that I attached is from 6.0.1. There is a substantial diff
between that and one from 5.2.0 tarball.

I played a little with "subplot",  "plotyy" and "hold on"
and results are bizarre. Perhaps it is a timing issue.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 15 Jun 2020 09:09:23 AM UTC, comment #4: 

I tested on Windows 10 with Octave 5.2.0 as it is installed with the "official" installer. I don't remember having changed any files locally. I compared "plotyy.m" with the version at the commit that is tagged as "release-5-2-0", and they are identical.

The different behavior we are seeing might depend on the CPU, memory, software vs. hardware rendering, ...

Since the original example also fails in Matlab (even though differently?), I don't know if it is worth pursuing this. If someone can provide a changeset, I'm happy to review though.

Does the changed example from comment #1 work for you?
It does for me in Octave 5.2.0 and with a recent build from the default branch on Windows 10.

Markus Mützel <mmuetzel>
Project Member
Sun 14 Jun 2020 11:43:58 PM UTC, comment #3: 

I also see that in 6.0.1 plotyy seems to ignore "hold on".

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sun 14 Jun 2020 11:04:11 PM UTC, comment #2: 

Markus, are you shure your plotyy is not patched?
I just recompile the pristine sourse ang can reproduce the error.
if I replace plotyy.m with the one from 6.0.1 I see no error.

(Attached fixed plotyy.m for the reference.)

Dmitri.
--

(file #49270)

Dmitri A. Sergatskov <dasergatskov>
Sun 14 Jun 2020 07:00:23 PM UTC, comment #1: 

I cannot confirm this here.

Running the function in Octave 5.2.0 doesn't provoke any errors for me. Also no lines seem to be missing.

I'm also attaching the output with Matlab R2020a where indeed not all lines seem to be in the final plots.

Anyhow, does creating the axes beforehand work for you? That seems to partially fix it for me in Matlab:

function chart_prob
  close all; figure;
  x = linspace(0,10,10);
  y = rand(4*4,10);
  for ip=1:4
    hax(ip) = subplot(2,2,ip);
  end
  % drawnow;  % Maybe you'll also need the drawnow here
  for ia=1:2
    for ip=1:4
      % hold on is commented, only 1 window-sized chart
      % is drawn: subplot above is ignored().
      hold on;
      grid on;
      iy = (ia-1)*4 + ip;
      % plot(x,y(iy,:)); does the right thing
      plotyy(hax(ip), x,y(iy,:), x,y(iy+1,:));
    end
  end
end


Markus Mützel <mmuetzel>
Project Member
Sun 14 Jun 2020 12:15:03 PM UTC, original submission:  

The following code shows two problems.  plotyy() generates a ton of 'error: get: invalid handle (= -1850.04)' warnings, and the first of four plot traces in each subplot aren't shown.  If the 'hold on' is commented out, then the subplot() window partitioning is ignored and only single chart is drawn.

The problem seems related to using subplot() to re-select a subplot that has already been plotted into; i.e. the second pass through the ia loop below.

Neither problem occurs if plot() is used instead of plotyy().

function chart_prob
  close all; figure;
  x = linspace(0,10,10);
  y = rand(4*4,10);
  for ia=1:2
    for ip=1:4
      subplot(2,2,ip);
      % hold on is commented, only 1 window-sized chart
      % is drawn: subplot above is ignored().
      hold on;
      grid on;
      iy = (ia-1)*4 + ip;
      % plot(x,y(iy,:)); does the right thing
      plotyy(x,y(iy,:), x,y(iy+1,:));
    end
  end
end

The only workaround I could find was to swap the for-ia and for-ip/subplot lines, so that subplot() is only called once per chart area.  Alas this is extremely difficult to do in my particular application: any other workaround ideas would be appreciated.

Neil Konzen <waterdog1>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #49270:  plotyy.m added by dasergatskov (9KiB - text/x-objcsrc)
file #49264:  chart_prob_Octave.png added by mmuetzel (154KiB - image/png)
file #49265:  chart_prob_Matlab.png added by mmuetzel (38KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Updated the item)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by waterdog1 (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 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-06-15 mmuetzel CategoryNone => Documentation
        StatusNeed Info => Confirmed
        Release5.2.0 => 6.0.90
        Operating SystemMicrosoft Windows => Any
    2020-06-14 dasergatskov Attached File- => Added plotyy.m, #49270
    2020-06-14 mmuetzel Attached File- => Added chart_prob_Matlab.png, #49265
        StatusNone => Need Info
    2020-06-14 mmuetzel Attached File- => Added chart_prob_Octave.png, #49264

    Back to the top


    Powered by Savane 3.5