bugGNU Octave - Bugs: bug #58526, "view(az, el)" does not...

 
 

bug #58526: "view(az, el)" does not work with gnuplot

Submitted by:  Daniel Molina García <dmolina>
Submitted on:  Mon 08 Jun 2020 12:28:37 AM UTC  
 
Category:  Plotting with gnuplot Severity:  3 - Normal
Priority:  3 - Low Item Group:  Incorrect Result
Status:  Works For Me Assigned to:  None
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

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)

Wed 21 Oct 2020 05:48:59 PM UTC, comment #24: 

I was trying to understand the cause of the strange behavior months ago, but it was very involved due my lack of experience on the octave core code. Finally I become busy with another project, so I did not have enough time to find the reason.

I understand that it is reasonable to ignore gnuplot issues if at some point it is going to be deprecated.

Daniel Molina García <dmolina>
Wed 21 Oct 2020 03:06:10 PM UTC, comment #23: 

Okay by me to close.

--Rik

Rik <rik5>
Project Administrator
Wed 21 Oct 2020 06:38:15 AM UTC, comment #22: 

Reading this issue:
- workarounds exist
- gnuplot is no longer focus of Octave development

@Rik or Daniel, what is here to test or can this one be closed?

Kai Torben Ohlhus <siko1056>
Project Member
Wed 21 Oct 2020 06:28:32 AM UTC, comment #21: 
Kai Torben Ohlhus <siko1056>
Project Member
Sat 13 Jun 2020 05:59:01 PM UTC, comment #20: 

First thing that I notice is that the .001 modification is needed also for me sometimes. The state in which I checked it before should be different.

Daniel Molina García <dmolina>
Sat 13 Jun 2020 05:46:18 PM UTC, comment #19: 

The main issue that I notice is that for a 2D projection using the trick

pos = get (gca, "position");
set (gca, "position", pos); # No need of .001 first

it increases the plotting area. However, as a downside if you change the view with the mouse it does not fit well in the window (comparison attached). That does not happen by setting the view using the command.

I will try to find why is "position" changing the behavior.


Daniel Molina García <dmolina>
Sat 13 Jun 2020 02:31:54 PM UTC, comment #18: 

I checked in the patch which at least makes things better.  We'll see if we start getting more bug reports about other strange behavior when plotting with gnuplot due to this.

I don't have time to debug why changing the "position" property makes gnuplot behave better, but there is still room for improvement if you're interested in looking deeper at this.

Rik <rik5>
Project Administrator
Thu 11 Jun 2020 12:54:01 AM UTC, comment #17: 

That's a consequence, again, of the one-way pipe Octave uses for communication with gnuplot.  If you shut the gnuplot window, or manipulate the plot by rotating it, Octave never knows about it.

Rik <rik5>
Project Administrator
Thu 11 Jun 2020 12:42:40 AM UTC, comment #16: 

I noticed now that view values (output of [az, el] = view()) is not updated when the view is changed by drawing the plot with the mouse in gnuplot. As a consequence, view(az, el) does not change the view unless az and el have different values that last registered values.

Daniel Molina García <dmolina>
Wed 10 Jun 2020 11:19:36 PM UTC, comment #15: 

It might be worth applying the patch, even if there is a potential for new problems.  If it really does start to break existing code then problems will be reported on the Bug Tracker and we can just revert the changeset.

Also, I think there is some weirdness going on with 3-D scenes with gnuplot.  You noted that the problem with using plot3 is that the plot is shrunk when moving to a 2-D view.  However, it seems that this is because the code is ignoring the size of the axes specified in the "position" property.  If I change the size of the axes, and then change back to the original size, gnuplot is forced to re-draw the plot and it turns out to look just fine.

Sample code

plot3 (x,y)
view (90, 90) # plot is small now
box on        # 2-D plot enables the box, plot3 does not, so I turn it on here
pos = get (gca, "position");
set (gca, "position", pos+.001);  # This produces an attractive plot
set (gca, "position", pos);       # This produces the same plot
                                  # .001 is below threshold for visual change

Rik <rik5>
Project Administrator
Wed 10 Jun 2020 10:22:04 PM UTC, comment #14: 

> I think that your solution is a good default, avoiding more complex code.


However, even if I don't know how much _calc_dimensions_ or other 2D/3D properties of a graphic object are used by other functions, maybe imposing a 3D without changing the internal details of the graph (type?) can result in other bugs as I pointed before.

Daniel Molina García <dmolina>
Wed 10 Jun 2020 10:07:31 PM UTC, comment #13: 

> The diff I posted works, but the visual results are similar to using camroll(), so you may still prefer to use various workarounds.


Yes. Using 3D reduces the plotting area in gnuplot when it is projected on 2D, also when view(az, el) is not explicitly used (just drawing the plot with the mouse). Now that I know more about how it works I think that it is better to not relay on view for 2D.

I think that your solution is a good default, avoiding more complex code. I tried to find some strange behavior for your diff  when a view of [0, 90] was set by drawing manually the plot with the mouse, but I was unable to arrive to that state, view() always returned [0, 91] when it was closer.

Daniel Molina García <dmolina>
Wed 10 Jun 2020 09:23:28 PM UTC, comment #12: 

The diff I posted works, but the visual results are similar to using camroll(), so you may still prefer to use various workarounds.

Rik <rik5>
Project Administrator
Wed 10 Jun 2020 09:21:38 PM UTC, comment #11: 

I think it may be difficult to discover, in practice, whether view() was the function that is resulting in _gnuplot_draw_axes_.m being called.

If you look at view.m, after calculating the correct azimuth and elevetation, it changes the property on the axes

    set (hax, "view", [az, el]);

I set a breakpoint within _gnuplot_draw_axes_.m and checked what the call stack was after the set statement and it is

dbstack
stopped in:

  -->   __gnuplot_draw_axes__ at line 33 [/home/rik/wip/Projects_Mine/octave-dev/scripts/plot/util/private/__gnuplot_draw_axes__.m]
      __gnuplot_draw_figure__ at line 169 [/home/rik/wip/Projects_Mine/octave-dev/scripts/plot/util/private/__gnuplot_draw_figure__.m]
          __gnuplot_drawnow__ at line 91 [/home/rik/wip/Projects_Mine/octave-dev/scripts/plot/util/__gnuplot_drawnow__.m]

There isn't any indication at this point which function resulted in redrawing the axes.  However, you might be able to modify the detection of dimensions.  The current code is

  nd = __calc_dimensions__ (h);

This diff changes things to enforce 3-D when the view is anything other than the default of [0, 90].

diff -r f5c9bb5955e7 scripts/plot/util/private/__gnuplot_draw_axes__.m
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m        Tue Jun 09 14:11:13 2020 -0700
+++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m        Wed Jun 10 14:20:06 2020 -0700
@@ -56,6 +56,10 @@ function __gnuplot_draw_axes__ (h, plot_
   endif

   nd = __calc_dimensions__ (h);
+  if (nd == 2 && (any (get (h, "view") != [0, 90])))
+    ## view() only works correctly on 3-D axes in gnuplot (bug #58526).
+    nd = 3;
+  endif

   if (strcmp (axis_obj.dataaspectratiomode, "manual")
       && strcmp (axis_obj.xlimmode, "manual")

(file #49239)

Rik <rik5>
Project Administrator
Wed 10 Jun 2020 08:14:29 PM UTC, comment #10: 

I have been debugging and I found that:

  • nd variable in scripts/plot/util/private/__gnuplot_draw_axes__.m is obtained through  _calc_dimensions_(h).
  • Return of _calc_dimensions_ is 2 if the axes were created with plot and 3 if it was created with plot3, independently of the graphic toolkit.
  • view(az, el) does not modify the value returned by _calc_dimensions_, independently of the graphic toolkit.

I think that function view(az, el), independently of az and el, should change the graphic object as if plot3 had been used to create it. That would solve this bug and probably others, since it would increase the consistency and any other function apart from _calc_dimensions_ would benefit from that.

I am not used to octave code yet, so maybe I am not considering something important.

Daniel Molina García <dmolina>
Mon 08 Jun 2020 11:14:15 PM UTC, comment #9: 

Thanks a lot for the alternative form of the workarounds and the guidelines to solve the error.

Daniel Molina García <dmolina>
Mon 08 Jun 2020 08:53:34 PM UTC, comment #8: 

Confirmed with gnuplot as backend.  Lowering priority as gnuplot is not a priority for Octave development.  You have already identified two workarounds

1) Use plot3() instead of plot(), and then choose a 2-D view

plot3 (x, y)
view (2)

2) Use plot() with reversed x, y arguments, and then reverse y-axis

plot (y, x)
axis ij

If you want a permanent fix, I would suggest beginning debuggin in scripts/plot/util/private/__gnuplot_draw_axes__.m.  There is code there that detects the number of dimensions (and places in variable "nd").  There are numerous tests later in the code that distinguish between 2-D and 3-D plots.

Rik <rik5>
Project Administrator
Mon 08 Jun 2020 06:39:30 PM UTC, comment #7: 

I want to be clear with respect to my use of view in subplots since my comment was nor precise.

  • camroll(-90) has the effect of reducing the plotting area and because of that I prefer view(90, 90) instead (see attached).
  • I didn't know that plot(X, Y, ...) accepts X as a matrix and Y a vector. Being that way, I find no difference between

plot (y, x)
set (gca, "ydir", "reverse")

and

plot (x, y)
view(90, 90)

Maybe the first form is preferred if "2D plots are not meant to be rotated [the second] way".


Daniel Molina García <dmolina>
Mon 08 Jun 2020 04:52:10 PM UTC, comment #6: 

I think that attachments were not uploaded. I try again.


Daniel Molina García <dmolina>
Mon 08 Jun 2020 04:50:01 PM UTC, comment #5: 

> Unable to reproduce.


I attach two figures of what I obtain with qt and with gnuplot.

> Try values for azimuth and elevation other than 90 degrees.


They don't work either.

> Also try drawnow.


Running drawnow after view doesn't correct the plot.

> And do try a 3D plot (plot3) before calling view.


With plot3 it works as expected, no bug in that case.

> 2D plots are not meant to be rotated that way.


I found that a solution to exchange x and y axes useful. I find it better than using view than using camroll in complex subplots where I want all subplots rotated. I find it more convenient than using something like plot(y,x) plus a reverse when there are different datasets in each subplot.

> view() works for me.  Try a 3-D plot example such as [..]


That example works for me too. It seems only a problem in 2D plot.

> Is there some reason the OP can't (or doesn't want to) use OpenGL plotting with the Qt toolkit?


Yes. In my main distribution only gnuplot is working. I commented it in Comment 2 of #58419. Before reporting bugs I check them in a virtual machine with Debian (screenshots come from there, so qt looks right).

Daniel Molina García <dmolina>
Mon 08 Jun 2020 04:01:53 PM UTC, comment #4: 

With OpenGL plotting, you can start with a 2D plot and display it as 3D just by changing the view.  That doesn't work for me with gnuplot.

OTOH, plotting with gnuplot is effectively deprecated and unmaintained unless there is someone who wants to work on it.  Is there some reason the OP can't (or doesn't want to) use OpenGL plotting with the Qt toolkit?

John W. Eaton <jwe>
Project Administrator
Mon 08 Jun 2020 03:53:31 PM UTC, comment #3: 

view() works for me.  Try a 3-D plot example such as

graphics_toolkit gnuplot
sombrero
[az, el] = view ()
pause (1)
view (45, 45)

Rik <rik5>
Project Administrator
Mon 08 Jun 2020 03:19:01 PM UTC, comment #2: 

And do try a 3D plot (plot3) before calling view. 2D plots are not meant to be rotated that way.

Anonymous
Mon 08 Jun 2020 03:17:41 PM UTC, comment #1: 

Unable to reproduce. A 2D plot already has an elevation of 90 degrees. Try values for azimuth and elevation other than 90 degrees. Also try drawnow.

Anonymous
Mon 08 Jun 2020 12:28:37 AM UTC, original submission:  

Maybe related to

#41583

That bug report is about values returned by view() and it is indicated the difficulty of getting information from gnuplot.

I am reporting that view(az, el) does not work with gnuplot. On the other hand, view() returns the intended values after used that way.

Example:

octave:1> graphics_toolkit gnuplot
octave:2> x = linspace (0, 10, 20);
octave:3> y = sqrt (x);
octave:4> plot (x, y)
octave:5> view (90, 90) # it does not change the plot
octave:6> [a, b] = view()
a = 90
b = 90

Daniel Molina García <dmolina>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #49251:  default.png added by dmolina (6KiB - image/png)
file #49252:  set_pos.png added by dmolina (7KiB - image/png)
file #49239:  bug58526.diff added by rik5 (602B - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by dmolina (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 15 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-10-22 siko1056 StatusReady For Test => Works For Me
        Open/ClosedOpen => Closed
    2020-06-13 dmolina Attached File- => Added default.png, #49251
        Attached File- => Added set_pos.png, #49252
    2020-06-13 rik5 Item GroupNone => Incorrect Result
        StatusConfirmed => Ready For Test
        Summary"view(az, el)" does not work => "view(az, el)" does not work with gnuplot
    2020-06-10 rik5 Attached File- => Added bug58526.diff, #49239
    2020-06-08 rik5 Priority5 - Normal => 3 - Low
        StatusWorks For Me => Confirmed
    2020-06-08 dmolina Attached File- => Added Screenshot@from@2020-06-08@20-13-54.png, #49229
        Attached File- => Added Screenshot@from@2020-06-08@20-15-17.png, #49230
    2020-06-08 dmolina Attached File- => Added Screenshot@from@2020-06-08@18-22-41.png, #49227
        Attached File- => Added Screenshot@from@2020-06-08@18-23-32.png, #49228
    2020-06-08 rik5 StatusNone => Works For Me

    Back to the top


    Powered by Savane 3.5