1

I am trying to make an interactive notebook (with voila) where I use ipyvolume for plotting a surface. However, I do not manage to set the camera correctly with ipyvolume. It should be a top-down view onto the z-direction. It works fine in the matplotlib case, but setting the same angle in ipyvolume does give me some 45º view. How can I get it to show the top down view?

If there is another way to achieve that, that's also be ok (needs to work in voila and be able to dynamically update the X, Y, Z and color data).

make data

import pandas as pd
import numpy as np
import ipyvolume as ipv

g = np.linspace(-np.pi/2, np.pi/2, 10)
X, Y = np.meshgrid(g, g, indexing='ij')
Z = np.sin(X**2+Y**2)

the ipyvolume plot

fig1 = ipv.figure()
mesh = ipv.plot_surface(X, Z, Y)
ipv.show()
ipv.pylab.view(90,-90)

enter image description here

the matpotib pot

fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(projection='3d')
ax.view_init(90, -90)
ax.set_xlabel('x')
ax.set_ylabel('y')
surf = ax.plot_surface(X, Y, Z)

enter image description here

Kamiccolo
  • 7,758
  • 3
  • 34
  • 47
John Smith
  • 1,059
  • 1
  • 13
  • 35

1 Answers1

0

It looks like you swapped Y and Z by accident in mesh = ipv.plot_surface(X, Z, Y), that could explain why you don't get the view you want. Once you make that change, the default view for ipyvolume (which is ipv.pylab.view(0,0)) appears to be the view you want. See code below, tested on google colab:

fig1 = ipv.figure()
mesh = ipv.plot_surface(X, Y, Z)
ipv.show()

And the output gives:

enter image description here

jylls
  • 4,395
  • 2
  • 10
  • 21
  • On top of that, you can use `ipv.view(0,0,distance)` to control the distance from your camera to your plot. – jylls Dec 23 '21 at 15:33
  • yes, you were right, the `X,Z,Y` was mixed up. Indeed the `ipv.view(0,0)` gets the direction correct. But you see that your figure still looks quite different compared to my matplotlib view. I tried increasing the distance, but it behaves very strange: e.g. `ipv.pylab.view(0, -1, 30)` should be very similar to `ipv.pylab.view(0, 0, 30)` (just 1 degree difference) but they look completely different for me. Is there a way to get the perspective similar to matplotlib? – John Smith Jan 05 '22 at 12:00
  • The difference in the way the figure looks only comes form the distance from th ecamera to the plot. ```mesh = ipv.plot_surface(X, Y, Z) ipv.pylab.view(0,0,6) ipv.show() ``` gives me a very similar result than the graph with matplotlib. – jylls Jan 06 '22 at 17:18
  • In my case, `ipv.pylab.view(0, -1, 30)` and `ipv.pylab.view(0, -1, 30)` do actually look very similar. I am using google colab – jylls Jan 06 '22 at 17:19