python条形图颜色设置_python – 根据值在matplotlib中更改3D条形图中的条形颜色

我在matplotlib中有一个3D条形图,总共有165个条形图,目前它非常混乱.

BFBS2.png

我想根据谨慎的z值更改条形的颜色:0,1,2.

我不确定如果我完全理解给定的答案,但我无法在这种情况下使其工作.

代码是:

data = [[0 0 0 2 0 0 1 2 0 0 0]

[0 0 2 2 0 0 0 0 2 0 0]

[1 0 2 2 1 2 0 0 2 0 2]

[1 0 2 2 0 2 0 2 2 2 2]

[2 2 2 2 2 2 2 2 2 2 2]

[2 2 0 2 2 2 2 2 2 2 2]

[0 2 2 0 2 2 2 2 2 2 2]

[1 2 0 0 2 1 2 2 0 0 2]

[0 0 2 1 0 0 2 0 0 0 0]

[2 1 2 2 0 0 0 2 0 0 2]

[2 2 2 0 2 0 0 0 2 2 2]

[2 2 0 0 2 2 2 2 2 0 0]

[2 2 1 2 0 0 0 2 2 2 0]

[2 0 0 2 0 0 2 2 2 2 2]

[2 0 0 2 0 2 2 2 2 2 2]]

ly = len(data[0])

lx = len(data[:,0])

xpos = np.arange(0,lx,1) # Set up a mesh of positions

ypos = np.arange(0,ly,1)

xpos, ypos = np.meshgrid(xpos+0.25, ypos+0.25)

xpos = xpos.flatten() # Convert positions to 1D array

ypos = ypos.flatten()

zpos = np.zeros(lx*ly)

dx = 0.5 * np.ones_like(zpos)

dy = dx.copy()

dz = data.flatten()

ys = np.array([float(yi) for yi in y[1:]])

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

# all blue bars

#ax.bar3d(xpos,ypos,zpos, dx, dy, dz, color='b')

# try changing color bars

colors = ['r','g','b']

for i in range(0,3):

ax.bar3d(xpos[i], ypos[i], zpos[i], dx, dy, dz[i], alpha=0.1,

color=colors[i])

ax.set_xlabel('X')

ax.set_ylabel('Y')

ax.set_zlabel('Z')

plt.show()

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值