Created
May 4, 2012 22:21
-
-
Save phobson/2598098 to your computer and use it in GitHub Desktop.
Plot a line with a colormap
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
# Props to Gökhan Sever for the idea | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.cm as cm | |
x = np.linspace(0, 3 * np.pi, 5000) | |
y = np.sin(x) | |
z = np.cos(0.5 * (x[:-1] + x[1:])) # 1st derivative | |
cmap_z = cm.coolwarm(z) | |
fig, ax1 = plt.subplots(nrows=1, ncols=1) | |
ax1.scatter(x, y, c=cmap_z, marker='_', s=5) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment