Last active
April 17, 2019 13:15
-
-
Save charlottenosam/c63b6caa68bd117e35a4c6a7ca98007d to your computer and use it in GitHub Desktop.
Plot lines with color defined by a parameter
This file contains 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
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
# Normalize the array vals so they can be mapped to a color | |
c_norm = mpl.colors.Normalize(vmin=np.min(array), vmax=np.max(array)) | |
# Pick a colormap | |
c_map = mpl.cm.viridis | |
# Scalar mappable of normalized array to colormap | |
s_map = mpl.cm.ScalarMappable(cmap=c_map, norm=c_norm) | |
s_map.set_array([]) | |
# Plot the lines | |
for value in array: | |
plt.plot(x, y_func(val), color=s_map.to_rgba(value)) | |
# Colorbar | |
plt.colorbar(s_map, label=r'Array Values') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment