簡體   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