3

I draw a plane and a line crossing the plane.

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3

def plot_x_axis(ax):
    x = np.array([-1, 1])
    y = np.array([0, 0])
    z = np.array([0, 0])
    ax.plot(x, y, z, color='green')

def plot_yz_plane(ax):
    a = np.array([0, 1, 0])
    b = np.array([0, 0, 1])
    U, V = np.meshgrid(np.linspace(-0.5, 0.5, 3), np.linspace(-0.5, 0.5, 3))
    x = a[0] * U + b[0] * V
    y = a[1] * U + b[1] * V
    z = a[2] * U + b[2] * V
    surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, alpha=1.0, color='red')

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plot_x_axis(ax)
plot_yz_plane(ax)
plt.show()

I expect that a part of this line (placed behind the plane) will be covered by the plane, but actually matplotlib shows all the objects as if the plane is transparent. How to fix this problem?

Maksim Surov
  • 603
  • 6
  • 22
  • 2
    as far as I can tell it is not possible using `matplotlib`. [check this question for further info](http://stackoverflow.com/questions/14824893/how-to-draw-diagrams-like-this/14825951#14825951) – Srivatsan Jun 09 '15 at 15:31
  • I'd like to record an animation showing a moving Poincare plane with some coordinate systems, descriptions, vector field, phase trajectory bla bla... it looks a bit tedious to draw everythibng in OpenGL. I am looking for a simple library for this. As far as I know VPython, Mayavi, VisPy does not allow to record video. Furthermore Mayavi has a bit strange user interface. VisPy requires to write shaders. Could u advise me a lib I am looking for? – Maksim Surov Jun 09 '15 at 15:47
  • I am sorry, I cannot help you any further! – Srivatsan Jun 09 '15 at 16:00
  • `Mayavi` can be used in a script and by saving figures I've made videos in a similar way to matplotlib. It is much better for 3D graphics. You need to write output to file using `mlab.savefig(filename)` and make a video with something like `ffmeg`. `Mayavi` uses pipelines, which are a little strange at first but you can do what you need, e.g. for vectors, you'd use `mlab.pipeline.vector_field(your data)` – Ed Smith Jun 10 '15 at 07:47

0 Answers0