python : plotting a wireframe 3D cuboid - python
I want to plot 3d cuboid in python.
Input :
center (3 points for the center)
radius (3 radius values, one for each dimension)
Ideally it should be a wireframe plot(I need to see whats inside).I am not exactly sure how to go about this. Using python matplotlib or Mayavi is fine.
Thanks!
So far I have tried the following code ..but that only draws a cube
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
#draw cube
r = [-1, 1]
for s, e in combinations(np.array(list(product(r,r,r))), 2):
if np.sum(np.abs(s-e)) == r[1]-r[0]:
ax.plot3D(*zip(s,e), color="b")
plt.show()
Whats missing in this code is that its only a cube(not a cuboid) and it's only centered around 0 (I actually want to provide the center)
After thinking a little bit I came up with this.Which seems right. Let me know if you think its not correct...this is the simplest possible way without installing myavi,pygame, povray (I had a hard time installing these on ipython, conda,my windows laptop)
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
#draw cube
r1 = [-1, 1]
r2 = [-2, 2]
r3 = [-3, 3]
center =[5,5,5]
for s, e in combinations(np.array(list(product(r1,r2,r3))), 2):
s=np.array(center)+np.array(s)
e=np.array(center)+np.array(e)
ax.scatter3D(*center, color="r")
if np.linalg.norm(s-e) == 2*r1[1] or np.linalg.norm(s-e) == 2*r2[1] or np.linalg.norm(s-e) == 2*r3[1]:
print zip(s,e)
ax.plot3D(*zip(s,e), color="b")
plt.show()
I have encountered the same question, and tried to give a answer as follows.
def cuboid_data(center, size):
"""
Create a data array for cuboid plotting.
============= ================================================
Argument Description
============= ================================================
center center of the cuboid, triple
size size of the cuboid, triple, (x_length,y_width,z_height)
:type size: tuple, numpy.array, list
:param size: size of the cuboid, triple, (x_length,y_width,z_height)
:type center: tuple, numpy.array, list
:param center: center of the cuboid, triple, (x,y,z)
"""
# suppose axis direction: x: to left; y: to inside; z: to upper
# get the (left, outside, bottom) point
o = [a - b / 2 for a, b in zip(center, size)]
# get the length, width, and height
l, w, h = size
x = [[o[0], o[0] + l, o[0] + l, o[0], o[0]], # x coordinate of points in bottom surface
[o[0], o[0] + l, o[0] + l, o[0], o[0]], # x coordinate of points in upper surface
[o[0], o[0] + l, o[0] + l, o[0], o[0]], # x coordinate of points in outside surface
[o[0], o[0] + l, o[0] + l, o[0], o[0]]] # x coordinate of points in inside surface
y = [[o[1], o[1], o[1] + w, o[1] + w, o[1]], # y coordinate of points in bottom surface
[o[1], o[1], o[1] + w, o[1] + w, o[1]], # y coordinate of points in upper surface
[o[1], o[1], o[1], o[1], o[1]], # y coordinate of points in outside surface
[o[1] + w, o[1] + w, o[1] + w, o[1] + w, o[1] + w]] # y coordinate of points in inside surface
z = [[o[2], o[2], o[2], o[2], o[2]], # z coordinate of points in bottom surface
[o[2] + h, o[2] + h, o[2] + h, o[2] + h, o[2] + h], # z coordinate of points in upper surface
[o[2], o[2], o[2] + h, o[2] + h, o[2]], # z coordinate of points in outside surface
[o[2], o[2], o[2] + h, o[2] + h, o[2]]] # z coordinate of points in inside surface
return x, y, z
def test():
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
center = [0, 0, 0]
length = 32 * 2
width = 50 * 2
height = 100 * 2
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = cuboid_data(center, (length, width, height))
ax.plot_surface(X, Y, Z, color='b', rstride=1, cstride=1, alpha=0.1)
ax.set_xlabel('X')
ax.set_xlim(-100, 100)
ax.set_ylabel('Y')
ax.set_ylim(-100, 100)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)
plt.show()
if __name__ == '__main__':
test()
This is the result:
Here is a wireframe plot for a cuboid.
def plot_cuboid(center, size):
"""
Create a data array for cuboid plotting.
============= ================================================
Argument Description
============= ================================================
center center of the cuboid, triple
size size of the cuboid, triple, (x_length,y_width,z_height)
:type size: tuple, numpy.array, list
:param size: size of the cuboid, triple, (x_length,y_width,z_height)
:type center: tuple, numpy.array, list
:param center: center of the cuboid, triple, (x,y,z)
"""
# suppose axis direction: x: to left; y: to inside; z: to upper
# get the (left, outside, bottom) point
import numpy as np
ox, oy, oz = center
l, w, h = size
x = np.linspace(ox-l/2,ox+l/2,num=10)
y = np.linspace(oy-w/2,oy+w/2,num=10)
z = np.linspace(oz-h/2,oz+h/2,num=10)
x1, z1 = np.meshgrid(x, z)
y11 = np.ones_like(x1)*(oy-w/2)
y12 = np.ones_like(x1)*(oy+w/2)
x2, y2 = np.meshgrid(x, y)
z21 = np.ones_like(x2)*(oz-h/2)
z22 = np.ones_like(x2)*(oz+h/2)
y3, z3 = np.meshgrid(y, z)
x31 = np.ones_like(y3)*(ox-l/2)
x32 = np.ones_like(y3)*(ox+l/2)
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
# outside surface
ax.plot_wireframe(x1, y11, z1, color='b', rstride=1, cstride=1, alpha=0.6)
# inside surface
ax.plot_wireframe(x1, y12, z1, color='b', rstride=1, cstride=1, alpha=0.6)
# bottom surface
ax.plot_wireframe(x2, y2, z21, color='b', rstride=1, cstride=1, alpha=0.6)
# upper surface
ax.plot_wireframe(x2, y2, z22, color='b', rstride=1, cstride=1, alpha=0.6)
# left surface
ax.plot_wireframe(x31, y3, z3, color='b', rstride=1, cstride=1, alpha=0.6)
# right surface
ax.plot_wireframe(x32, y3, z3, color='b', rstride=1, cstride=1, alpha=0.6)
ax.set_xlabel('X')
ax.set_xlim(-100, 100)
ax.set_ylabel('Y')
ax.set_ylim(-100, 100)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)
plt.show()
def test():
center = [0, 0, 0]
length = 32 * 2
width = 50 * 2
height = 100 * 2
plot_cuboid(center, (length, width, height))
if __name__ == '__main__':
test()
Here is the result.
Everybody forgets about POVray that handles 3D very well. It doesn't render wireframe, though, but you can use a half-transparent texture to see what is inside of the box.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
center='-1, -1, -1'
radius='1, 1, 1'
pov='camera { location <0, 2, -3> look_at <0, 1, 2> }\n\
light_source { <2, 4, -3> color rgb 1*1.5}\n\
background {color rgb <0.00, 0.00, 0.00>}\n\
box {<'+center+'>, < '+radius+'>\n\
pigment { color rgbt <0.67, 1.00, 0.39, 0.80> }\n\
rotate <52, 6, 0>\n\
scale 0.9\n\
translate <0, 1.2, 1>}\n\
'
f=open('scene.pov', 'w')
f.write(pov)
f.close()
os.system('povray +W400 +H300 +A +FN scene.pov')
Output "scene.png"
You need to read povray's documentation.
Related
How to relate size parameter of .scatter() with radius?
I want to draw some circles using `ax3.scatter(x1, y1, s=r1 , facecolors='none', edgecolors='r'), where: x1 and y1 are the coordinates of these circles r1 is the radius of these circles I thought typing s = r1 I would get the correct radius, but that's not the case. How can I fix this?
If you change the value of 'r' (now 5) to your desired radius, it works. This is adapted from the matplotlib.org website, "Scatter Plots With a Legend". Should be scatter plots with attitude! import numpy as np import matplotlib.pyplot as plt np.random.seed(19680801) fig, ax = plt.subplots() for color in ['tab:blue', 'tab:orange', 'tab:green']: r = 5 #radius n = 750 #number of circles x, y = np.random.rand(2, n) #scale = 200.0 * np.random.rand(n) scale = 3.14159 * r**2 #CHANGE r ax.scatter(x, y, c=color, s=scale, label=color, alpha=0.3, edgecolors='none') ax.legend() ax.grid(True) plt.show()
Make 3D triangle lines more visible in pyplot
I'd like to make a triangle plot in matplotlib with a mostly-transparent surface. I'm running the example code at https://matplotlib.org/mpl_examples/mplot3d/trisurf3d_demo.py: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np n_radii = 8 n_angles = 36 # Make radii and angles spaces (radius r=0 omitted to eliminate duplication). radii = np.linspace(0.125, 1.0, n_radii) angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False) # Repeat all angles for each radius. angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) # Convert polar (radii, angles) coords to cartesian (x, y) coords. # (0, 0) is manually added at this stage, so there will be no duplicate # points in the (x, y) plane. x = np.append(0, (radii*np.cos(angles)).flatten()) y = np.append(0, (radii*np.sin(angles)).flatten()) # Compute z to make the pringle surface. z = np.sin(-x*y) fig = plt.figure() ax = fig.gca(projection='3d') ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True) plt.show() I can set ax.plot_trisurf(x, y, z, linewidth=0.2, alpha = 0.2, antialiased=True) to set the opacity to 0.2, but then the lines disappear. Furthermore, when I change the linewidth, even without the alpha, I see no change in the thickness of the lines between the points. How can I have a triangle plot where the faces are mostly transparent and the lines are clearly visible?
How to order ax.scatter and ax.quiver in Python 3D plot?
I want to draw a spin systems. I have the picture below. However, I want the quivers to be INSIDE the scatter circles and the "Main arrow" to be a bright one. Thus, how can I order three plots? Thank You in advance! Here is the code: import matplotlib.pyplot as plt from matplotlib import cm, colors from mpl_toolkits.mplot3d import Axes3D import numpy as np ############################## A sphere ################################# r = 4 pi = np.pi cos = np.cos sin = np.sin phi, theta = np.mgrid[0.0:pi:100j, 0.0:2.0*pi:100j] x = r*sin(phi)*cos(theta) y = r*sin(phi)*sin(theta) z = r*cos(phi) #Set colours and render fig = plt.figure(figsize=(10,10)) ax = fig.add_subplot(111, projection='3d') ax.plot_surface(x, y, z, rstride=1, cstride=1, color='red', alpha=0.6, linewidth=0) ############################ One arrow ######################## x1 = 0 y1 = 0 z1 = 0 dx1 = 0 dy1 = 0 dz1 = 2 ax.quiver(x1, y1, z1, dx1, dy1, dz1, pivot='middle', color="blue", linewidths=5.0,length=1.4) ax.scatter(0, 0, 0,color="blue", s=800) ############################ Array of arrows ############################################ ax.set_xlim([-4,4]) ax.set_ylim([-4,4]) ax.set_zlim([-4,4]) ax.set_aspect("equal") plt.tight_layout() N = 5 # number of points - 5x5x5 scale = 0.4 # scale for the increment of an arrow ax = fig.gca(projection='3d') xx = np.linspace(-3.5, 3.5, N) yy = np.linspace(-3.5, 3.5, N) zz = np.linspace(-3.5, 3.5, N) dxx = scale*np.random.rand(N) dyy = scale*np.random.rand(N) dzz = scale*np.random.rand(N) x, y, z = np.meshgrid(yy, zz, xx) dx, dy, dz = np.meshgrid(dxx, dyy, dzz) ax.scatter(x, y, z,color="orange", s=200) ax.quiver(x, y, z, dx, dy, dz, pivot='middle', length=1.6, color="blue") plt.show()
fix graphic isometric figure
I Have the following code taken from Here, in this code a figure of height two is generated by two cubes (upper and bottom), I want generate the figure of height two by a only one figure, likewise the figure of height 3,4,5,... import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt def cuboid_data(center, N, size=(1,1,1)): # code taken from # https://stackoverflow.com/questions/30715083/python-plotting-a-wireframe-3d-cuboid?noredirect=1&lq=1 # suppose axis direction: x: to left; y: to inside; z: to upper # get the (left, outside, bottom) point o = [a - b / 2 for a, b in zip(center, size)] l, w, h = size x = [[o[0], o[0] + l, o[0] + l, o[0], o[0]], # x coordinate of points in bottom surface [o[0], o[0] + l, o[0] + l, o[0], o[0]], # x coordinate of points in upper surface [o[0], o[0] + l, o[0] + l, o[0], o[0]], # x coordinate of points in outside surface [o[0], o[0] + l, o[0] + l, o[0], o[0]]] # x coordinate of points in inside surface y = [[o[1], o[1], o[1] + w, o[1] + w, o[1]], # y coordinate of points in bottom surface [o[1], o[1], o[1] + w, o[1] + w, o[1]], # y coordinate of points in upper surface [o[1], o[1], o[1], o[1], o[1]], # y coordinate of points in outside surface [o[1] + w, o[1] + w, o[1] + w, o[1] + w, o[1] + w]] # y coordinate of points in inside surface z = [[0,0,0,0,0], [N,N,N,N,N], [0, 0, N,N, 0], [0, 0, N, N, 0]] return x, y, z def plotCubeAt(pos=(0,0), N=0, ax=None): # Plotting N cube elements at position pos if ax !=None: if N > 0: #for n in range(N): X, Y, Z = cuboid_data( (pos[0],pos[1],N),N ) ax.plot_surface(X, Y, Z, color='y', rstride=1, cstride=1)#,linewidth=0) def plotIsoMatrix(ax, matrix): # plot a Matrix # where matrix[i,j] cubes are added at position (i,j) for i in range(matrix.shape[0]): for j in range(matrix.shape[1]): plotCubeAt(pos=(i,j), N=matrix[i,j], ax=ax) l = max(matrix.shape[0], matrix.shape[1], matrix.max()) #bb = np.array([(0,0,0), (0,l,0), (l,0,0), (l,l,0),(0,0,l), (0,l,l), (l,0,l), (l,l,l)]) #ax.plot(bb[:,0], bb[:,1], bb[:,2], "w", alpha=0.0) if __name__ == '__main__': fig = plt.figure() ax = fig.gca(projection='3d') #ax.set_aspect('equal') matrix = np.array([[2,2],[1,2]]) plotIsoMatrix(ax, matrix) #ax.set_axis_off() plt.ion() plt.show() This generate the following figure: I want to generate the following figure: How fix this ? Thanks
Solution usiing matplotlib First of all, if you do not want to have single cubes, but cuboids, there is a much simpler solution - using matplotlib bar3d. import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_aspect('equal') matrix = np.array([[2,2],[1,2]]) xpos, ypos = np.meshgrid(np.arange(matrix.shape[0]),np.arange(matrix.shape[1]) ) xpos = xpos.flatten('F') ypos = ypos.flatten('F') zpos = np.zeros_like(xpos) dx = np.ones_like(zpos) dy = dx.copy() dz = matrix.flatten() ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='y', zsort='average', linewidth=0) l = max(matrix.shape[0], matrix.shape[1], matrix.max()) bb = np.array([(0,0,0), (0,l,0), (l,0,0), (l,l,0),(0,0,l), (0,l,l), (l,0,l), (l,l,l)]) ax.plot(bb[:,0], bb[:,1], bb[:,2], "w", alpha=0.0) ax.set_axis_off() plt.show() Concerning the overlapping faces of the cuboids, there is no solution in matplotlib. I think this behaviour is commonly considered to be an unresolvable bug, as is also described in the Matplotlib 3D FAQ. Also, manually setting zorder will not work. The good news is, however, that this overlapping is angle dependent. So you will always find a viewing angle (rotate the plot with the mouse) where it looks good. Solution using mayavi Using Mayavi, one does not have the problem of overlapping faces at all. Also the barchart in mayavi is much more convenient, making this only 5 lines of code: import numpy as np import mayavi.mlab as mlab mlab.figure(bgcolor=(1,1,1)) matrix = np.array([[2,2],[1,2]]) mlab.barchart(matrix, color=(1.,0.86, 0.12), lateral_scale=1.0) mlab.show()
How do you create a 3D surface plot with missing values matplotlib?
I am trying to create a 3D surface energy diagram where an x,y position on a grid contains an associated z level. The issue is that the grid is not uniform (ie, there is not a z component for every x,y position). Is there a way to refrain from plotting those values by calling them NaN in the corresponding position in the array? Here is what I have tried so far: import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D import pylab from matplotlib import cm #Z levels energ = np.array([0,3.5,1,-0.3,-1.5,-2,-3.4,-4.8]) #function for getting x,y associated z values? def fun(x,y,array): return array[x] #arrays for grid x = np.arange(0,7,0.5) y = np.arange(0,7,0.5) #create grid X, Y = np.meshgrid(x,y) zs = np.array([fun(x,y,energ) for x in zip(np.ravel(X))]) Z = zs.reshape(X.shape) plt3d = plt.figure().gca(projection='3d') #gradients now with respect to x and y, but ideally with respect to z only Gx, Gz = np.gradient(X * Y) G = (Gx ** 2 + Gz ** 2) ** .5 # gradient magnitude N = G / G.max() # normalize 0..1 plt3d.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=cm.jet(N), edgecolor='k', linewidth=0, antialiased=False, shade=False) plt.show() I cannot post image here of this plot but if you run the code you will see it But I would like to not plot certain x,y pairs, so the figure should triangle downward to the minimum. Can this be accomplished by using nan values? Also would like spacing between each level, to be connected by lines. n = np.NAN #energ represents the z levels, so the overall figure should look like a triangle. energ = np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,2.6,n,2.97,n,2.6,n,2.97,n,2.6,n,3.58,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,1.09,n,1.23,n,1.09,n,1.23,n,1.7,n,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,-0.65,n,-0.28,n,-0.65,n,0.33,n,n,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,n,-2.16,n,-2.02,n,-1.55,n,n,n,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,n,n,-3.9,n,-2.92,n,n,n,n,n,],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,n,n,n,-4.8,n,n,n,n,n,n,]]) plt3d = plt.figure().gca(projection='3d') Gx, Gz = np.gradient(X * energ) # gradients with respect to x and z G = (Gx ** 2 + Gz ** 2) ** .5 # gradient magnitude N = G / G.max() # normalize 0..1 x = np.arange(0,13,1) y = np.arange(0,13,1) X, Y = np.meshgrid(x,y) #but the shapes don't seem to match up plt3d.plot_surface(X, Y, energ, rstride=1, cstride=1, facecolors=cm.jet(N), edgecolor='k', linewidth=0, antialiased=False, shade=False ) Using masked arrays generates the following error: local Python[7155] : void CGPathCloseSubpath(CGMutablePathRef): no current point. n = np.NAN energ = np.array([[0,0,0,0,0,0,0,0,0,0,0,0,0],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,2.6,n,2.97,n,2.6,n,2.97,n,2.6,n,3.58,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,1.09,n,1.23,n,1.09,n,1.23,n,1.7,n,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,-0.65,n,-0.28,n,-0.65,n,0.33,n,n,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,n,-2.16,n,-2.02,n,-1.55,n,n,n,n],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,n,n,-3.9,n,-2.92,n,n,n,n,n,],[n,n,n,n,n,n,n,n,n,n,n,n,n],[n,n,n,n,n,n,-4.8,n,n,n,n,n,n,]]) x = np.arange(0,13,1) y = np.arange(0,13,1) X, Y = np.meshgrid(x,y) #create masked arrays mX = ma.masked_array(X, mask=[[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,0,1,0,1,0,1,0,1,0,1,0,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,0,1,0,1,0,1,0,1,0,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,0,1,0,1,0,1,0,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,0,1,0,1,0,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,0,1,0,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,0,1,1,1,1,1,1]]) mY = ma.masked_array(Y, mask=[[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,0,1,0,1,0,1,0,1,0,1,0,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,0,1,0,1,0,1,0,1,0,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,0,1,0,1,0,1,0,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,0,1,0,1,0,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,0,1,0,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,0,1,1,1,1,1,1]]) m_energ = ma.masked_array(energ, mask=[[0,0,0,0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,0,1,0,1,0,1,0,1,0,1,0,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,0,1,0,1,0,1,0,1,0,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,0,1,0,1,0,1,0,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,0,1,0,1,0,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,0,1,0,1,1,1,1,1],[1,1,1,1,1,1,1,1,1,1,1,1,1],[1,1,1,1,1,1,0,1,1,1,1,1,1]]) plt3d = plt.figure().gca(projection='3d') plt3d.plot_surface(mX, mY, m_energ, rstride=1, cstride=1, edgecolor='k', linewidth=0, antialiased=False, shade=False) plt.show()
I was playing around with the code from this forum post, and I was able to make the graph have missing values. You can try the code yourself! I got it to work using float("nan") for the missing values. import plotly.graph_objects as go import numpy as np x = np.arange(0.1,1.1,0.1) y = np.linspace(-np.pi,np.pi,10) #print(x) #print(y) X,Y = np.meshgrid(x,y) #print(X) #print(Y) result = [] for i,j in zip(X,Y): result.append(np.log(i)+np.sin(j)) result[0][0] = float("nan") upper_bound = np.array(result)+1 lower_bound = np.array(result)-1 fig = go.Figure(data=[ go.Surface(z=result), go.Surface(z=upper_bound, showscale=False, opacity=0.3,colorscale='purp'), go.Surface(z=lower_bound, showscale=False, opacity=0.3,colorscale='purp')]) fig.show()