Python Forum
Three-dimensional Contour Plots - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Three-dimensional Contour Plots (/thread-12806.html)



Three-dimensional Contour Plots - minifizikus - Sep-13-2018

Hi. I am beginner in Python programming. I want to do a Three-dimensional Contour Plots, like this: https://jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-plotting.html . Why the code is not working? I know that "figure" is not declared in main...how can I do this? which are other mistakes in code? Can anyone write the full correct code?
from matplotlib.pyplot import axis
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = plt.axes(projection='3d')
def f(x,y):
    return np.sin(np.sqrt(x ** 2 + y ** 2))

x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)

X, Y = np.meshgrid(x, y)
Z = f(X, Y)

fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z, 50, cmap='binary')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z');
ax.view_init(60, 35)
fig



RE: Three-dimensional Contour Plots - Larz60+ - Sep-13-2018

here's a tutorial you may want to look at: https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html

or this one: https://matplotlib.org/examples/mplot3d/surface3d_demo.html