我已经浏览了许多问题,但找不到我要找的内容或只是不明白。(我是新手)。
我有一个函数 f(q, t) = 2q(1-t)
我想为 q 和 t 的所有组合绘制 f(q, t),假设 q 在 (0, 1] 中,t 在 [0, 1)U(1, 2] 中。
我没有要显示的代码,因为我不确定从哪里开始。谢谢你。
R 或 Python 都可以。
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def f(x, y):
return 2 * x * (1 - y)
x = np.linspace(0, 1, 50)
y = np.union1d(np.linspace(0, 0.99, 50), np.linspace(1.01, 2, 50))
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure(figsize=(12,8))
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z, 100, cmap='binary')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z');
基本上,您只需要调整此处给出的示例:https : //jakevdp.github.io/PythonDataScienceHandbook/04.12-three-dimensional-plotting.html。该脚本是不言自明的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句