现在有一些统计数据绘制在 (x, y) 上的 3d 条中。每个条形高度表示 (x,y) 平面方形网格中点的密度。现在,我可以在每个条上添加不同的颜色。但是,我想在 3d 条上放置渐进色,类似于 cmap,因此条将根据密度进行渐变填充。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# height of the bars
z = np.ones((4, 4)) * np.arange(4)
# position of the bars
xpos, ypos = np.meshgrid(np.arange(4), np.arange(4))
xpos = xpos.flatten('F')
ypos = ypos.flatten('F')
zpos = np.zeros_like(xpos)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = z.flatten()
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
plt.show() …Run Code Online (Sandbox Code Playgroud) matplotlib ×1