pythonmatplotlibscattercolorbar

Partially transparent scatter plot, but with a solid color bar


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…


Solution

  • Joe Kington's comment is the correct way to do this as matplotlib 6.0 has deprecated cbar.draw_all():

    import matplotlib.pyplot as plt
    fig, ax = plt.subplots()
    im = ax.scatter(range(10), range(10), c=range(10), alpha=0.2)
    cbar = fig.colorbar(im, ax=ax)
    cbar.solids.set(alpha=1)
    

    The deprecation warning:
    MatplotlibDeprecationWarning: The draw_all function was deprecated in Matplotlib 3.6 and will be removed two minor releases later. Use fig.draw_without_rendering() instead. cbar.draw_all()