将颜色映射应用于mpl_toolkits.mplot3d.Axes3D.bar3d [英] apply color map to mpl_toolkits.mplot3d.Axes3D.bar3d

查看:88
本文介绍了将颜色映射应用于mpl_toolkits.mplot3d.Axes3D.bar3d的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Axes3D的bar3d函数有一个'color'参数,该参数可以接受数组以给各个条形上不同的颜色-但是我将如何以与plot_surface函数相同的方式应用颜色图(即cmap = cm.jet)例子 ?这将使一定高度的条成为反映其高度的颜色.

There is a 'color' argument to Axes3D's bar3d function which can accept arrays to color individual bars different colors - but how would I apply a color map (i.e. cmap = cm.jet) in the same way as a plot_surface function for example ? This would make a bar of a certain height a color which reflects its height.

http://matplotlib.sourceforge.net/examples/mplot3d/hist3d_demo.html

http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/api.html

推荐答案

这是我的解决方案:

offset = dz + np.abs(dz.min())
fracs = offset.astype(float)/offset.max()
norm = colors.normalize(fracs.min(), fracs.max())
colors = cm.jet(norm(fracs))

ax.bar3d(xpos,ypos,zpos,1,1,dz, color=colors)

仅当数据为负时才需要第一行.

The first line is only required if your data goes negative.

从此处改编的代码 http://matplotlib.sourceforge.net/examples/pylab_examples/hist_colormapped.html .

这篇关于将颜色映射应用于mpl_toolkits.mplot3d.Axes3D.bar3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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