Skip to content Skip to sidebar Skip to footer

Correct Way To Set Color To Transparent With Matplotlib.pcolormesh()?

I would like values under a certain level (in this case 0) to be plotted as transparent with matplotlib.pcolormesh(), and I cannot seem to get anything working with the options tha

Solution 1:

You can use a masked array:

import matplotlib.pyplotas plt
import numpy as np

z = np.sin(np.arange(100) / 2).reshape(10, 10)
z = np.ma.masked_array(z, z < -.5)

cmap = plt.cm.Reds
plt.pcolormesh(z, vmin=-1, vmax=1, cmap="RdYlBu")
plt.colorbar()

enter image description here

Post a Comment for "Correct Way To Set Color To Transparent With Matplotlib.pcolormesh()?"