python条形图和散点图_在Python和matplotlib的3D散点图中的两点之间绘制一个矩形或条形...

我认为使用PolyCollection会更容易.这跟你所追求的很接近吗?

import matplotlib.pyplot

from mpl_toolkits.mplot3d import Axes3D

from matplotlib.collections import PolyCollection

import random

dates = [20020514, 20020515, 20020516, 20020517, 20020520]

highs = [1135, 1158, 1152, 1158, 1163]

lows = [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')

verts = []; fcs = []

for i in range(len(dates)-1):

xs = [dates[i],dates[i+1],dates[i+1],dates[i],dates[i]] # each box has 4 vertices, give it 5 to close it, these are the x coordinates

ys = [highs[i],highs[i+1],lows[i+1],lows[i], highs[i]] # each box has 4 vertices, give it 5 to close it, these are the y coordinates

verts.append(zip(xs,ys))

fcs.append((random.random(),random.random(),random.random(),0.6))

poly = PolyCollection(verts, facecolors = fcs, closed = False)

ax.add_collection3d(poly, zs=[zaxisvalues0[0]] * len(verts), zdir='y') # in the "z" just use the same coordinate

ax.scatter(dates, zaxisvalues0, highs, color = 'g', marker = "o")

ax.scatter(dates, zaxisvalues0, lows, color = 'y', marker = "^")

matplotlib.pyplot.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值