谢谢你的帮助亚历克西斯和马克。我想现在已经解决了。在
我用了亚历克西斯的提示来使用'zdir'属性。在As for the wrong plane problem, you can fix it with parameter zdir,
for instance ax.bar(dates, highs,zdir='y',bottom=highs, zs=0, color = 'b') – Alexis
一开始,它生成的条形图是应该的两倍高,因为它是从底部测量的(即“低”值),然后再加上一个高度(从“高”值)。在
所以我最后引入了一个新的列表“位移”,它测量每个高点和每个低点之间的距离(在这个过程中,我发现我的低点和高点互换了。嗯,很抱歉)。所以现在我在画“位移”而不是高点。在
我在Alexis的线条上添加了宽度、对齐、边缘颜色和alpha(透明度);然后加厚了轴向散射阴谋。现在代码工作了(好吧,几乎,除了第四条上的箭头比它应该的高。。。嗯)import matplotlib.pyplot
from mpl_toolkits.mplot3d import Axes3D
dates = [20020514, 20020515, 20020516, 20020517, 20020520]
lows = [1135, 1158, 1152, 1158, 1163]
highs = [1257, 1253, 1259, 1264, 1252]
upperLimits = [1125.0, 1125.0, 1093.75, 1125.0, 1125.0]
lowerLimits = [1250.0, 1250.0, 1156.25, 1250.0, 1250.0]
zaxisvalues0= [0, 0, 0, 0, 0]
zaxisvalues1= [1, 1, 1, 1, 1]
zaxisvalues2= [2, 2, 2, 2, 2]
fig = matplotlib.pyplot.figure()
ax = fig.add_subplot(111, projection = '3d')
ax.plot(dates, zaxisvalues1, lowerLimits, color = 'b')
ax.plot(dates, zaxisvalues2, upperLimits, color = 'r')
ax.scatter(dates, zaxisvalues0, highs, color = 'g', marker = "^", linewidth=4)
ax.scatter(dates, zaxisvalues0, lows, color = 'y', marker = "o", linewidth=4)
displacements = []
for i in lows:
position = lows.index(i)
disp = highs[position] - i
displacements.append(disp)
ax.bar(dates, displacements, zdir='y', bottom=lows, zs=0, width=0.2, align='center', alpha=0.6, edgecolor='k')
matplotlib.pyplot.show()
结果是: