【发布时间】:2016-06-28 21:57:23
【问题描述】:
我使用以下代码制作了一个简单的 3d 条形图:
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")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.set_xlim3d(0,10)
ax.set_ylim3d(0,10)
ax.set_zlim3d(0,2)
xpos = [2,5,8,2,5,8,2,5,8]
ypos = [1,1,1,5,5,5,9,9,9]
zpos = np.zeros(9)
dx = np.ones(9)
dy = np.ones(9)
dz = np.ones(9)
ax.bar3d(xpos, ypos, zpos, dx, dy, dz)
plt.gca().invert_xaxis()
plt.show()
把这当作一个测试,到目前为止一切似乎都很清楚。我只是想知道如何以堆叠的方式绘制这 9 个条形图中的每一个,例如每个条分为 4 个部分,构成整个条。
基本上,我正在考虑以示例here. 的方式这样做
但是,我想要 4 个,而不是 2 个堆栈。有什么想法可以从我现在的位置开始吗?非常感谢每一个提示。
谢谢!
编辑:如果我想为每个堆叠条实现给定值,例如:
...
z = [np.array([ 0.2, 0.6, 0.3, 0.6, 0.4, 0.3, 0.8, 0.5, 0.7]),
np.array([ 0.8, 0.4, 0.5, 0.2, 0.8, 0.7, 0.4, 0.2, 0.9]),
np.array([ 0.1, 0.2, 0.4, 0.4, 0.2, 0.6, 0.3, 0.6, 0.9]),
np.array([ 0.9, 0.5, 0.7, 0.2, 0.5, 0.6, 0.7, 0.9, 0.7])]
dz = [z for i in range(4)]
...
这似乎不起作用,我不知道为什么?
【问题讨论】:
-
我做了类似here 的操作,但您可能会在使用 matplotlib 绘制深度信息的方式时遇到困难。不过,我的回答应该适用于您的问题,只有您必须更改
zpos而不是条形图的颜色/不透明度。
标签: python matplotlib charts 3d