Следующий код должен работать для вас:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import get_test_data
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
def randrange(n, vmin, vmax):
'''
Helper function to make an array of random numbers having shape (n, )
with each number distributed Uniform(vmin, vmax).
'''
return (vmax - vmin)*np.random.rand(n) + vmin
def graficar(fun):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
x = y = np.arange(-1.0, 1.0, 0.05)
X, Y = np.meshgrid(x, y)
zs = np.array(fun(np.ravel(X), np.ravel(Y)))
Z = zs.reshape(X.shape)
ax.plot_surface(X, Y, Z)
title = 'Graficación de la función'
ax.set_title(title)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
(xs, ys, zs) = ([0, 0.2, 1, 1.2, 0.3],
[-0.2, 0.3, 1.8, 0.7, 1.0], [1.0, 0.6, 0.4, 0.9, -0.5])
ax.scatter(xs, ys, zs, c='r', marker='^')
plt.show()
# funcion x**2 + y**2
def funcion1(x, y):
return (x)**2 + (y)**2
graficar(funcion1)
Это даст вам следующий график:
