Skip to content

Instantly share code, notes, and snippets.

@dkirkby
Last active May 20, 2020 18:36
Show Gist options
  • Save dkirkby/55980e339342e8b50d45c6153ef9fed5 to your computer and use it in GitHub Desktop.
Save dkirkby/55980e339342e8b50d45c6153ef9fed5 to your computer and use it in GitHub Desktop.
# Reuse the automatically selected color from a plot
line2d = plt.plot([0, 1], [0, 1], ':')
plt.scatter([0, 1], [0, 1], c=line2d[0].get_color())
# Reuse the automatically selected color from a scatter
pathcol = plt.scatter([0, 1], [0, 1])
plt.plot([0, 1], [0, 1], c=pathcol.get_fc()[0], ls=':')
# Use the j-th default color
c = plt.rcParams['axes.prop_cycle'].by_key()['color'][j]
# Specify a default color explicitly via Ck
for k, y in enumerate(...):
plt.plot(x, y, '.', c=f'C{k}')
plt.plot([], [], '-', c=f'C{k}', label=str(k))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment