0

I have the following code to draw the plane x+y+z=1, but unfortunately although I set the limits to [0,1] for all the variables it still draws the continuation in the negative area. How can I only get the surface bounded to x,y,z>0 area?

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.ticker import LinearLocator, FormatStrFormatter

point  = np.array([1, 0, 0])
normal = np.array([1, 1, 1])
fig = plt.figure()
ax = fig.gca(projection='3d')

# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d = -point.dot(normal)

# create x,y
X = np.arange(0, 1, 0.02)
Y = np.arange(0, 1, 0.02)
X, Y = np.meshgrid(X, Y)

# calculate corresponding z
Z = (-normal[0] * X - normal[1] * Y - d) * 1. /normal[2]
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
        linewidth=0, antialiased=False)

ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

plt.show()

Find a trick myself but this is hack rather than a correct way of doing it: Added up the following lines:

Y[Z<0]=None
X[Z<0]=None
Z[Z<0]=None
Cupitor
  • 11,007
  • 19
  • 65
  • 91
  • The hack generates a corrupted version of the plane! – Cupitor Nov 10 '13 at 15:36
  • I've been trying and I can't find a way. It seems to me like set_zlim etc. are bugged? For me, they only limit the axes and don't clip the data. – KobeJohn Nov 10 '13 at 16:58
  • 1
    Confirmed. This is a [bug](https://github.com/matplotlib/matplotlib/issues/749/). From the close notes: "Therefore, I am closing this issue as "wontfix", but note that if/when mpl gains an OpenGL backend, this may change." – KobeJohn Nov 10 '13 at 17:07

0 Answers0