5

I have a numpy array vertices of shape (N,3) containing the N vertices of a spherical polygon in 3D, i.e. all these points lie on the surface of a sphere. The center and radius of the sphere is known (take the unit sphere for example). I would like to plot the spherical polygon bounded by these vertices. (Mathematically speaking, I want to plot the spherically convex hull generated by these vertices).

How can I do that using matplotlib? I tried Poly3DCollection, but this only plots the Euclidean polygon. I managed to plot the entire unit sphere using plot_surface like this:

u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = np.outer(np.cos(u), np.sin(v))
y = np.outer(np.sin(u), np.sin(v))
z = np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z, rstride=5, cstride=5, color='y', alpha=0.1)

I guess one could manually calculate what points to remove from x, y, z and then still use plot_surface in order to plot the polygon. Would this be the correct way to use matplotlib or does it have another module, which I could use directly?

In case there is no convenient way to do this in matplotlib, can you recommend any other library, which does that?

ali_m
  • 71,714
  • 23
  • 223
  • 298
Meneldur
  • 215
  • 1
  • 5
  • 1
    `matplotlib` is pretty limited for 3D plotting, as a result I ended up doing something similar to what you have above. I found `mayavi` is better suited but ends up being a little more involved, check out the official website (http://docs.enthought.com/mayavi/mayavi/auto/examples.html) and this page (http://indranilsinharoy.com/2014/03/02/plotting-algebraic-surfaces-using-mayavi/) for a sphere example. – Ed Smith Sep 22 '15 at 13:31
  • Is [this](http://stackoverflow.com/a/29872732/1461210) what you're looking for? – ali_m Nov 07 '15 at 01:27

0 Answers0