apply color map to mpl_toolkits.mplot3d.Axes3D.bar3d

前端 未结 3 1502
耶瑟儿~
耶瑟儿~ 2020-12-18 10:48

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 =

3条回答
  •  伪装坚强ぢ
    2020-12-18 11:05

    Here is my solution:

    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.

    Code adapted from here http://matplotlib.sourceforge.net/examples/pylab_examples/hist_colormapped.html.

提交回复
热议问题