繁体   English   中英

如何使用 function plot_surface 中的 plot 3D 图?

[英]How to plot 3D diagram using function plot_surface in matplotlib?

我的代码如下所示:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

x_points = np.linspace(1, 3, num=3)
y_points = np.linspace(1, 6, num=6)
z_points = np.linspace(1, 10, num=10)

x_points, y_points, z_points = np.meshgrid(x_points, y_points, z_points)
x_points = x_points.flatten().reshape(60, 3)
y_points = y_points.flatten().reshape(60, 3)
z_points = z_points.flatten().reshape(60, 3)

# To simplify the problem and illustrate my point, suppose that there exists some kind of function
# relationship among x_points, y_points, z_points and u values.
u = f(x_points, y_points, z_points)

# bounds for normalization: minSpeed & maxSpeed
u = (u - minSpeed) / (maxSpeed - minSpeed)
fig = plt.figure()
ax = fig.gca(projection='3d')
im = ax.plot_surface(x_points, y_points, z_points, facecolors=cm.coolwarm(u), linewidth=0, antialiased=False, shade=False)

我想 plot 3D 图用 u 值表示 colors。 我在网上搜索了关于function plot_surface,写了上面的代码。 但它没有像我预期的那样给出 plot 。 如何修改代码以达到我的目的?

plot_surface允许显示 function Z 的 2 个变量的变化(例如Z=np.sqrt(X**2 + Y**2) ),但您在这里考虑的是 function U 的 3 个变量 X, Y和Z。

建议您通过此处提供的源代码示例熟悉plot_surface

如果您确实在尝试显示“4D 图”,请查看此答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM