Created
September 11, 2025 05:57
-
-
Save wassname/b24f09ce60dde0dd13e915a9ee2005f0 to your computer and use it in GitHub Desktop.
matplotlib generator colors from cmap and norm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to use matplotlib to assign a spectrum of colors to lines in a plot, | |
import matplotlib as mpl | |
strengths = [-2, -1, 0, 2, 3] | |
v = max(np.abs(strengths)) | |
cnorm = mpl.colors.CenteredNorm(0, v) | |
cmap = mpl.cm.coolwarm | |
for s in strengths: | |
plt.plot(x, y, c=cmap(norm(s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment