matplotlib not displaying intersection of 3D planes correctly

matplotlib, matplotlib-3d, python

Solution

See How to draw intersecting planes? for a long explanation + possible work around.

The short answer in that matplotlib's 3D support is clever use of projections to generate a 2D view of the 3D object which is then rendered to the canvas. Due to the way that matplotlib renders (artist at a time) one artist is either fully above or fully below another. If you need real 3D support look into `mayavi`.

Problem

I want to plot two planes and find their intersection line, but I get this result, where it's impossible to tell where they intersect, because one plane overlays the other. A 3D projection should hide the non-visible part of the plane, how do I attain this result using matplotlib? You can clearly see that these to plains should intersect. Here's the code I've used to get this result ``` import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D values = range(-10, 11) def plotPlane(plot, normal, d, values, colorName): # x, y, z x, y = np.meshgrid(values, values) z = (-normal[0] * x - normal[1] * y - d) * 1. / normal[2] # draw plot plot.plot_surface(x, y, z, color=colorName) image = plt.figure().gca(projection='3d') plotPlane(image, [3, 2, -4], 1, values, "red") plotPlane(image, [5, -1, 2], 4, values, "gray") plt.show() ```

Original source

Related problems