I'm attempting to use Python and Matplotlib to render a 3D surface of a polyhedron, given by
However my code (shown below) does not seem to draw it correctly. How should this be done instead?
Failed Attempt:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
delta = 0.1
def x_func(x):
return abs(x)
def y_func(y):
return abs(y)
def z_func(z):
return abs(z)
x = np.arange(-1, 1, delta)
x1 = x_func(x)
y = np.arange(-1, 1, delta)
y1 = y_func(y)
X, Y = meshgrid(x1, y1)
z = np.arange(-1, 1, delta)
Z = z_func(z)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([-1,1])
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.RdBu, linewidth=0.1)

