Skip to content Skip to sidebar Skip to footer

Scatter Plot With Same Color For Values Below A Threshold

I am trying to generate a scatter plot of coordinates(x,y) where the color is decided by a value ranging between (-3,1.5). How do I plot all the points with value less than -1 with

Solution 1:

vmin and vmax indicate which c-value corresponds to the lowest and highest colors of the color map. Default, all values lower than vmin get the lowest color (dark purple for the 'viridis' map). You can change this color with cmap.set_under(...). The extend= parameter shows the under color as a triangular arrow in the colorbar.

from matplotlib import pyplot as plt
import numpy as np

x = np.linspace(0, 15, 50)
y = - np.sin(x) / (x + 1) * 8
num_colors = 10
cmap = plt.get_cmap('viridis', num_colors)
cmap.set_under('red')
plt.scatter(x, y, c=y, cmap=cmap, vmin=-1, vmax=1.5)
plt.colorbar(extend='min')
plt.show()

example plot

Post a Comment for "Scatter Plot With Same Color For Values Below A Threshold"