Python Forum

Full Version: Three-dimensional Contour Plots
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I am beginner in Python programming. I want to do a Three-dimensional Contour Plots, like this: https://jakevdp.github.io/PythonDataScie...tting.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