1

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.

enter image description 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()
Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174

1 Answers1

2

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.

Community
  • 1
  • 1
Greg
  • 11,654
  • 3
  • 44
  • 50
  • Thanks so much for the headsup! Yes, I am ok with LaTeX. So I just write the Tikz codes like I am writing the paper in Texmaker, and compile it using texmaker? Will that work? – Sibbs Gambling Sep 03 '13 at 08:04
  • 1
    Yes exactly, just be sure to include all the preamble (e.g copy and paste everything from one of the examples into a blank tex document). In general it is best to compile it outside the document your inserting it in as it can slow down the compile quite a bit, then import the resulting pdf as an image. – Greg Sep 03 '13 at 08:09
  • 1
    OMG, really amazed by how the powerful tools (LaTeX and Python here) can be related! Will try later. If encounter any problem, may come back and call you again. Thanks very much! :) – Sibbs Gambling Sep 03 '13 at 08:18
  • 1
    If you _really_ want to do it it matplotlib, you will have to split your shape up in to pieces to get the in-front of/behind relationships correct (see http://stackoverflow.com/questions/14824893/how-to-draw-diagrams-like-this/14825951#14825951) – tacaswell Sep 03 '13 at 14:44