I want to plot 3D contour lines in python.
I have a (50,50,50)-shaped data. (f(x,y,z)=data)
Using this, I want to draw contour lines, and each line with the same color.
I can draw about 2-dimensional data, but I don't know how to handle 3-dimensional data.
I use the library plotly, But this is surface plot.
I want to get lines.
Which library should I use?
Here is my code.
import numpy as np
import plotly.graph_objects as go
n = 50
x = np.linspace(-8,8,n)
y = np.linspace(-8,8,n)
z = np.linspace(0,20,n)
X, Y, Z = np.meshgrid(x,y,z)
Bstr = np.loadtxt("Bstr.txt", delimiter=',')
Bstr2 = np.zeros(n**3).reshape(n,n,n)
for i in range(n):
for j in range(n):
for k in range(n):
Bstr2[i][j][k] = Bstr[n**2*i+n*j+k]
fig = go.Figure(data=go.Isosurface(
x=X.flatten(),
y=Y.flatten(),
z=Z.flatten(),
value=Bstr2.flatten(),
opacity=0.5,
surface_count=7, # number of isosurfaces, 2 by default: only min and max
colorbar_nticks=5, # colorbar ticks correspond to isosurface values
caps=dict(x_show=False, y_show=False)
))
fig.show()