'Draw relation in matplotlib [closed]
I have a relation such as 'x^3 + y^3 + z^3 - c = 0'. c is constant and would be any number, and of course the equation may be changed. How can i draw this surface with python? I don't want to explicit find z=f(x,y)
Solution 1:[1]
If you are using Jupyter Notebook and Python, the easiest way that I know of to visualize 3D implicit surfaces is K3D-Jupyter's Marching Cube algorithm.
import k3d
import numpy as np
plot = k3d.plot()
r = 5
zmin, zmax = -r, r
xmin, xmax = -r, r
ymin, ymax = -r, r
N = 100
Nx, Ny, Nz = N, N, N
x = np.linspace(xmin, xmax, Nx, dtype=np.float32)
y = np.linspace(ymin, ymax, Ny, dtype=np.float32)
z = np.linspace(zmin, zmax, Nz, dtype=np.float32)
x, y, z = np.meshgrid(x, y, z, indexing='ij')
p = x**3 + y**3 + z**3 - 2
plt_iso = k3d.marching_cubes(
p,
level=0.0, compression_level=9,
xmin=xmin, xmax=xmax,
ymin=ymin, ymax=ymax,
zmin=zmin, zmax=zmax,
flat_shading=False)
plot += plt_iso
plot.display()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ann Zen |