user1459139
user1459139

Reputation: 53

How to change contour colors in a range of values

Colormap class in matplotlib has nice methods set_over and set_under, which allow to set color to be used for out-of-range values on contour plot.

But what if I need to set color to be used in a range of values, e.g. white out values from -0.1 to 0.1? Is there a method set_between(colormap, interval, color)? If not, what would be the easiest solution?

Upvotes: 3

Views: 562

Answers (1)

cjohnson318
cjohnson318

Reputation: 3253

You could use the NumPy where function to replace values in a specified range to the overall maximum or minimum value, and that would effectively whiten or blacken those values in your plot.

q = np.random.normal( 0, 1, (10,10) )
np.where( ( q > -.1 ) & ( q < .1 ), np.max( q ), q )

Upvotes: 1

Related Questions