Matplotlib bar3d变量alpha [英] Matplotlib bar3d variable alpha

查看:84
本文介绍了Matplotlib bar3d变量alpha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Matplotlib bar3d与RdBu颜色图一起使用,并希望在各个条之间具有可变的透明度(因此,较小的条可以比较高的条更透明).

I'm using matplotlib bar3d with RdBu colormap and wanted to have variable transparency between bars (so smaller bars can be more transparent than taller bars).

这里是制作3d条形图的代码.数据存储在4x4矩阵"rho"中.目前,alpha保持在0.95,但是最好能够控制每个小节的alpha值.

Here is the code for making the 3d bar plot. The data is stored in a 4x4 matrix 'rho'. At the moment alpha is kept at 0.95, but it would be excellent to be able to control the value of alpha for each bar.

欢呼

xpos = np.arange(0,4,1)
ypos = np.arange(0,4,1)
xpos, ypos = np.meshgrid(xpos, ypos)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(4*4)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = rho.flatten()
nrm=mpl.colors.Normalize(-1,1)
colors=cm.RdBu(nrm(-dz))
alpha = 0.95
ax.bar3d(xpos,ypos,zpos, dx, dy, dz, alpha=alpha, color=colors, linewidth=0)

推荐答案

xpos = np.arange(0,4,1)
ypos = np.arange(0,4,1)
xpos, ypos = np.meshgrid(xpos, ypos)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(4*4)
rho = np.random.random((4,4))
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = rho.flatten()
nrm=mpl.colors.Normalize(-1,1)
colors=cm.RdBu(nrm(-dz))
alpha = np.linspace(0.2, 0.95, len(xpos), endpoint=True)
fig = plt.figure()
ax = fig.gca(projection='3d')
for i in range(len(xpos)):
    ax.bar3d(xpos[i],ypos[i],zpos[i], dx[i], dy[i], dz[i], alpha=alpha[i], color=colors[i], linewidth=0)
plt.show()

这篇关于Matplotlib bar3d变量alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆