0
A
回答
0
您可以在3 d條形圖中設置bottom
,只是一樣的2-d:
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')
colors = ['r', 'g', 'b', 'y']
for i, (c, z) in enumerate(zip(colors, [30, 20, 10, 0])):
xs = np.arange(20)
ys = np.random.rand(20)
ys2 = np.random.rand(20)
ys3 = np.random.rand(20)
# You can provide either a single color or an array. To demonstrate this,
# the first bar of each set will be colored cyan.
cs = [c] * len(xs)
cs[0] = 'c'
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
ax.bar(xs, ys2, bottom=ys, zs=z, zdir='y', color=colors[(i+1)%4], alpha=0.8)
ax.bar(xs, ys3, bottom=ys+ys2, zs=z, zdir='y', color=colors[(i+2)%4], alpha=0.8)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
1
您還可以使用bar3d做到這一點:在zpos參數允許你設置酒吧的底部。此處作爲一例基於從matplotlib例子演示代碼(hist3d_demo.py)
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')
x, y = np.random.rand(2, 100) * 4
hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]])
# Construct arrays for the anchor positions of the 16 bars.
# Note: np.meshgrid gives arrays in (ny, nx) so we use 'F' to flatten xpos,
# ypos in column-major order. For numpy >= 1.7, we could instead call meshgrid
# with indexing='ij'.
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
xpos = xpos.flatten('F')
ypos = ypos.flatten('F')
# z position set to zero
zpos = np.zeros_like(xpos)
# Construct arrays with the dimensions for the 16 bars.
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
# Create a random second histogram
dz2 = dz * np.random.rand(16)
# Set z position to the values of the first histogram
zpos2 = dz
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average', alpha=0.7)
ax.bar3d(xpos, ypos, zpos2, dx, dy, dz2, color='r', zsort='average', alpha=0.7)
plt.show()
相關問題
- 1. Matlab:3D堆積條形圖
- 2. 堆積條形圖
- 3. D3條形圖堆積條形圖
- 4. likert堆積條形圖
- 5. D3tip和堆積條形圖
- 6. Matplotlib堆積的條形圖
- 7. Ext-gwt堆積條形圖
- 8. 100%堆積條形圖
- 9. 分組多條堆積條形圖
- 10. d3過渡堆積條形圖
- 11. URL在堆積條形圖每箱
- 12. 軸定製在SSRS堆積條形圖
- 13. 結合堆積和並排條形圖
- 14. 熊貓 - 劇情堆積條形圖
- 15. jqplot並排堆積條形圖
- 16. 如何在堆積條形圖
- 17. 2列ggplot堆積條形圖
- 18. D3中的動態堆積條形圖
- 19. d3js更新重繪堆積條形圖
- 20. 帶填充ggplot2的堆積條形圖
- 21. jpgraph堆積條形圖進入底部
- 22. 與多個yAxis的堆積條形圖
- 23. 劍道堆積條形圖類別
- 24. 在r中創建堆積條形圖
- 25. Angular4中的堆積條形圖
- 26. R:ggplot堆積條形圖傳說倒掛
- 27. 碧玉報告堆積條形圖:
- 28. Highcharts堆積條形圖:如何吧
- 29. 堆積和分組條形圖
- 30. gnuplot的堆積條形圖算術