Skip to content

Instantly share code, notes, and snippets.

@siddharthpaliwal
Created October 16, 2019 09:53
Show Gist options
  • Save siddharthpaliwal/b5313d40871c751baa253aef9d4b6b92 to your computer and use it in GitHub Desktop.
Save siddharthpaliwal/b5313d40871c751baa253aef9d4b6b92 to your computer and use it in GitHub Desktop.
Matplotlib color cycler indexing
cycle = plt.rcParams['axes.prop_cycle'].by_key()['color']
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(5)
for i in range(4):
line, = ax.plot(t,i*(t+1), linestyle = '-')
ax.plot(t,i*(t+1)+.3,color = line.get_color(), linestyle = ':')
fig = plt.figure()
ax = fig.add_subplot(111)
t = np.arange(5)
cmap = plt.get_cmap("tab10")
for i in range(4):
ax.plot(t,i*(t+1), color=cmap(i), linestyle = '-')
ax.plot(t,i*(t+1)+.3,color=cmap(i), linestyle = ':')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment