Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib中的三维条形图问题_Python_3d_Matplotlib_Bar Chart - Fatal编程技术网

Python Matplotlib中的三维条形图问题

Python Matplotlib中的三维条形图问题,python,3d,matplotlib,bar-chart,Python,3d,Matplotlib,Bar Chart,当我用4个或更多的值制作一个3d条形图时,图形看起来是正确的,但是当我用3个条形图尝试时,条形图变成三角形,发生了什么 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') color_grade_classes = ['#80FF00','#

当我用4个或更多的值制作一个3d条形图时,图形看起来是正确的,但是当我用3个条形图尝试时,条形图变成三角形,发生了什么

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')

color_grade_classes = ['#80FF00','#FFFF00','#FF8000', '#FF0000']

for colors, rows  in zip(color_grade_classes, [3,2,1,0] ):  
  indexs = np.arange(3)
  heights = np.random.rand(3)
  print rows, indexs, heights, colors

  ax.bar(indexs, heights, zs = rows,  zdir='y', color=colors, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')

plt.show()
生成以下内容:

但是,当我将索引和高度的数量增加到5时,我得到:


这是因为您只给它3个点进行绘图。只要把代码改成下面的代码,它就可以工作了

indexs = np.arange(4)  # not 3
heights = np.random.rand(4) # not 3

这几乎肯定是一个bug。尝试您的示例代码,可以得到任意点数的矩形条的理想结果(使用1、2、3、5、15进行测试):

我正在linux上运行matplotlib版本1.1.1rc。如果可以,请尝试更新到最新版本。注意

导入matplotlib
打印matplotlib.\u版本__

将告诉您正在使用的版本。

这看起来像是一个可能的错误。有3个三角形和2个条形,它不会绘制它们。。。windows 7 matplotlib 1.1.0有人知道在matplotlib中哪里可以报告错误吗?请参阅此处的“报告问题”:在OS X 10.7.4上的Python 2.7.3/matplotlib 1.1.1上,代码也可以按预期工作,因此它确实可能是一个错误。