EnneKappa
EnneKappa

Reputation: 239

Transparent colormap

I would like to get a density distribution plot with the alpha channel instead of the blue channel.

I found this code but it doesn't work.

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)

Upvotes: 4

Views: 7379

Answers (1)

Yann
Yann

Reputation: 35463

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.

Upvotes: 2

Related Questions