title: How can I plot 3D contour lines in python?
body: <p><a href="https://i.stack.imgur.com/I3c6s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I3c6s.png" alt="enter image description here" /></a>I want to plot 3D contour lines in python.</p>
  <p>I have a (50,50,50)-shaped data. (f(x,y,z)=data)</p>
  <p>Using this, I want to draw contour lines, and each line with the same color.</p>
  <p>I can draw about 2-dimensional data, but I don't know how to handle 3-dimensional data.</p>
  <p>I use the library plotly, But this is surface plot.</p>
  <p>I want to get lines.</p>
  <p>Which library should I use?</p>
  <p>Here is my code.</p>
  <pre><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(&quot;Bstr.txt&quot;, 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()
  </code></pre>