Skip to content

Instantly share code, notes, and snippets.

@pierdom
Last active September 6, 2017 12:04
Show Gist options
  • Select an option

  • Save pierdom/6ddf7b4f2cdf458971c71a9e8d07ecf7 to your computer and use it in GitHub Desktop.

Select an option

Save pierdom/6ddf7b4f2cdf458971c71a9e8d07ecf7 to your computer and use it in GitHub Desktop.
[Cycle over colors in Matplotlib] Frist create a color map ('cm') of a given palette, the tell to bin the color map (depending on the number of requested colors, in the example taken from the size of an array). Now, every time we plot to the axe 'ax', we get the next color automatically #matplotlib #visualization
# new solution (N is the number of elements)
ax.set_prop_cycle('color',plt.cm.rainbow(np.linspace(0,1,N)))
# the solution below is deprecated
cm = plt.get_cmap('gist_rainbow')
ax.set_color_cycle([cm(1.*i/len(YOUR_LIST)) for i in np.arange(len(YOUR_LIST))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment