Partially transparent scatter plot, but with a solid color bar

Eric O Lebigot picture Eric O Lebigot · Dec 18, 2010 · Viewed 33k times · Source

In Python, with Matplotlib, how to simply do a scatter plot with transparency (alpha < 1), but with a color bar that represents their color value, but has alpha = 1?

Here is what one gets, with from pylab import *; scatter(range(10), arange(0, 100, 10), c=range(10), alpha=0.2); color_bar = colorbar():

alt text

How can the color bar be made non-transparent?

PS: I tried color_bar.set_alpha(1); draw(), but this did not do anything…

Answer

Eric O Lebigot picture Eric O Lebigot · Dec 18, 2010

Alright, I found one way to do it, that looks relatively clean: (using the ColorBar object from the question)

color_bar.set_alpha(1)
color_bar.draw_all()
# pylab.draw() or pyplot.draw() might be necessary

It would be great to get a confirmation that this is the most robust way to proceed, though! :)