Last active
September 6, 2017 12:04
-
-
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
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
| # 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