Tricontourf - don't display some color

Hi,

I visualize some data on a tricontourf plot that I parametrized like that :
tricontourf(x, y,
triangles,
values,
vmin=0,
vmax=np.max(values),
cmap=‘jet’)

What i want is not to display all the value less than 0.

I’ve tried using “mask” options but it hides the whole triangles i designed to mask :

tricontourf makes a shading and i don’t want to lose this shading, i only want to not display the color for value less than 0.

Thanks in advance.

You can set the “under” color that the color map uses https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap.set_under

import matplotlib.cm as mcm
import copy
cmap = copy.copy(mcm.get_cmap('viridis'))
cmap.set_under('w')
tricontourf(x, y, triangles, values,
            vmin=0,
            vmax=np.max(values),
            cmap=cmap)

Alternatively, specify the levels that you want to contour starting at zero:

import matplotlib.pyplot as plt
import numpy as np

x = [0.0, 1.0, 0.5]
y = [0.0, 0.0, 0.5]
triangles = [[0, 1, 2]]
values = [-2.0, 5.0, 3.0]

plt.tricontourf(x, y, triangles, values, levels=np.arange(0, 5.1, 1), cmap='jet')
plt.colorbar()
plt.show()

test