GLSurfacePlotItem on polar grid

48 views
Skip to first unread message

Jeremy Swearingen

unread,
Jan 4, 2020, 11:09:28 PM1/4/20
to pyqtgraph

Is there a way to get GLSurfacePlotItem to plot a surface on a polar grid, rather than filling out the corners of an x, y grid. For example, I'm able to get a simple parabolic shape with matplotlib (see matplotlib attachment) with the following code.

### With matplotlib

from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
from coordinates import *

r = np.linspace(0, 10, 100)
theta = np.linspace(0, 2*np.pi, 100)
rr, tt = np.meshgrid(r, theta)

xx, yy = pol_to_cart(rr, tt) # simple conversion function between coordinate systems

zz = xx**2 + yy**2

fig = plt.figure()
ax = plt.axes(projection='3d')

ax.plot_surface(xx, yy, zz, cmap='viridis', edgecolor='none')
plt.show()

###

The best I can get with pyqtgraph is shown in the other attachment, and is achieved with the following code.

### With pyqtgraph

x = np.linspace(-7, 7, 100)
y = np.linspace(-7, 7, 100)
xx, yy = np.meshgrid(x, y)

zz = xx**2 + yy**2

self.surf = gl.GLSurfacePlotItem(x = x, y = y, z = zz, shader = 'shaded')

All of my attempts to do something similar to what I did with matplotlib end in weirdness. Maybe because of how matplot lib takes mesh inputs for x, y, and z, instead of just z? I thought it might be something like the following

### Failed attempt

r = np.linspace(0, 10, 100)
theta = np.linspace(0, 2*np.pi, 100)
rr, tt = np.meshgrid(r, theta)

x, y = pol_to_cart(rr, tt) # simple conversion function between coordinate systems
xx, yy = pol_to_cart(rr, tt) # simple conversion function between coordinate systems

zz = xx**2 + yy**2

self.surf = gl.GLSurfacePlotItem(x = x, y = y, z = zz, shader = 'shaded')

###

But that produces nonsense. Thanks.
Matplotlib.PNG
pyqtgraph.PNG

Jeremy Swearingen

unread,
Jan 4, 2020, 11:12:50 PM1/4/20
to pyqtgraph
My failed attempt should actually read:

### Failed attempt

r = np.linspace(0, 10, 100)
theta = np.linspace(0, 2*np.pi, 100)
rr, tt = np.meshgrid(r, theta)

x, y = pol_to_cart(r, theta) # simple conversion function between coordinate systems
xx, yy = pol_to_cart(rr, tt) # simple conversion function between coordinate systems

Grant R

unread,
Jan 5, 2020, 11:10:32 PM1/5/20
to pyqtgraph
There are assumptions made about x and y that don't apply in your case. If you don't reshape x here and y further down in the code, then you get what you expect I believe. Supporting two-dimensional x and y would seem like a useful addition and a relatively simple one at that.
Reply all
Reply to author
Forward
0 new messages