How to change scatter plot color according to certain rule
问题 I have to do a scatter plot that has colors depending on a third variable. If the variable is between 0 and 1, give "blue", 1-2, red, 2-3, purple, 3-4, green, 4-5 gray. How can I do that ? x = [1,2,3,4,5] y = [3,4,2,3,4] c = [1,2,4,0.5,5] 回答1: If you want specific boundaries for the colormap you can use mpl.colors.BoundaryNorm together with mpl.colors.ListedColormap . import matplotlib.pyplot as plt import matplotlib as mpl x = [1,2,3,4,5] y = [3,4,2,3,4] c = [1,2,4,0.5,5] cmap = mpl.colors