[英]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 。 如何修改代碼以達到我的目的?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.