简体   繁体   中英

How to plot sectors in 3D with Matplotlib?

I wish to have two sectors (one in blue color, the other in black pencil) in 3D , and they share the same vertex on the plane. The black pencil one lies on the plane, whereas the blue one is theta above the plane.

The effect I am expecting is shown as the picture here.

在此处输入图片说明

It would be nice if I can also mark the three angles out.

What I have tried:

from matplotlib.patches import Wedge
from matplotlib.collections import PatchCollection
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
patches = []
patches.append(Wedge((.8,.3), .2, 0, 45))
p = PatchCollection(patches)
ax.add_collection3d(p)
plt.show()

The issue you will ultimately run into is that matplotlib 3d is only a projection of shapes, and does not try to render an object in 3d.

It is possible and well demonstrated in this post but I advise you run the code from @Lileth's answer to see where the projection limits you.

Alternatives exist such as:

  • Mayavi where you could use mesh() , defining two arrays for the shapes.

  • If you are familiar with Latex, Tikz is capable of producing fantastic 3d plots, but the learning curve is quite steep -- in general it is best to choose the example closest to what you want and hack rather than go from scratch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM