如何获得 4D 绘图 Matplotlib 的颜色图中使用的色标
How do I get the color scale used in the colormap for 4D plot Matplotlib
我有一个 4D 图:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
x = np.arange(100)/ 101
y = np.sin(x) + np.cos(x)
X,Y = np.meshgrid(x,y)
Z = (X**2) / (Y**2)
A = np.sin(Z)
fig = plt.figure()
ax = fig.add_subplot(111,projection= '3d' )
ax.plot_surface(X,Y, Z, facecolors=cm.Oranges(A))
plt.show()
输出图像
但是如何查看颜色图的比例?
您需要从颜色图创建一个可映射的
m = cm.ScalarMappable(cmap=cm.Oranges)
m.set_array(A)
cbar = plt.colorbar(m)
就像这个问题的答案一样:
我有一个 4D 图:
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
x = np.arange(100)/ 101
y = np.sin(x) + np.cos(x)
X,Y = np.meshgrid(x,y)
Z = (X**2) / (Y**2)
A = np.sin(Z)
fig = plt.figure()
ax = fig.add_subplot(111,projection= '3d' )
ax.plot_surface(X,Y, Z, facecolors=cm.Oranges(A))
plt.show()
输出图像
但是如何查看颜色图的比例?
您需要从颜色图创建一个可映射的
m = cm.ScalarMappable(cmap=cm.Oranges)
m.set_array(A)
cbar = plt.colorbar(m)
就像这个问题的答案一样: