【发布时间】:2020-12-23 00:56:56
【问题描述】:
我使用 Matplotlib 将一个简单的函数绘制为 3D 图。现在,我想创建一个颜色图来根据u 和v 函数中派生的速度对其进行着色。为此,我想使用c 中的函数。我该怎么做呢?提前谢谢你。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.linspace(-2, 2, 20)
y = np.linspace(-2, 2, 20)
X, Y = np.meshgrid(x, y)
h = np.exp(-X**2 - Y**2) # plotted function
u = -2*X*np.exp(-X**2 - Y**2) # speed in x-direction
v = -2*Y*np.exp(-X**2 - Y**2) # speed in y-direction
c = np.sqrt(u**2 + v**2) # colormap derives from this
fig = plt.figure(figsize = (8, 7), facecolor='white')
ax = fig.add_subplot(projection='3d')
ax.plot_surface(X, Y, h)
plt.show()
【问题讨论】:
-
请看link。
标签: python numpy matplotlib simulation colormap