Transparent colormap

為{幸葍}努か 提交于 2020-01-01 10:35:47

问题


I would like to get a density distribution plot like this density http://www.nicolacarlon.it/out.png with the alpha channel instead of the blue channel like this density http://www.nicolacarlon.it/out2.png

I found this code but it doesn't works :(

    theCM = cm.get_cmap()
    theCM._init()
    alphas = np.abs(np.linspace(-1.0, 1.0, theCM.N))
    theCM._lut[:-3,-1] = alphas
    plt.imshow(img, cmap=theCM)
    plt.savefig("out.svg", transparent=True)

回答1:


This is a bug with the Colormap class of matplotlib. It exists in 0.99.x versions of matplotlib, but has been fixed as of 1.x. See the bug fix for a description of how it was fixed. Upgrade to the latest version and this problem should be fixed. There is not a work around for this bug, so upgrading is the only option.



来源:https://stackoverflow.com/questions/8580631/transparent-colormap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!