Skip to content

Instantly share code, notes, and snippets.

@phobson
Created May 4, 2012 22:21
Show Gist options
  • Save phobson/2598098 to your computer and use it in GitHub Desktop.
Save phobson/2598098 to your computer and use it in GitHub Desktop.
Plot a line with a colormap
# 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