I am answering my question to post details and explanations of the solution you are using, because the mwaskom suggestion required customization. Using
with reversed(sns.color_palette('Blues_d', n_colors=n_plots)):
throws AttributeError: __exit__ , I believe, because the with statement requires an object with the __enter__ and __exit__ methods, which the reversed iterator does not satisfy. If I use sns.set_palette(reversed(palette)) instead of the with operator, the number of colors on the graph is ignored (the default value is 6 - I donβt know why), even if the color scheme is executed. To solve this problem, I use the list.reverse() method:
figure = plt.figure(1) x = range(1, 200) n_plots = 10 palette = sns.color_palette("Blues_d", n_colors=n_plots) palette.reverse() with palette: for offset in range(n_plots): plt.plot(x, [offset + math.sin(float(i) / 10) for i in range(len(x))]) figure.show()
Edit: I found that the reason the n_colors argument was ignored when calling set_palette was because the n_colors argument should also be specified in this call. Another solution:
figure = plt.figure(1) x = range(1, 200) n_plots = 10 sns.set_palette(reversed(sns.color_palette("Blues_d", n_plots)), n_plots) for offset in range(n_plots): plt.plot(x, [offset + math.sin(float(i) / 10) for i in range(len(x))]) figure.show()
Ninjakannon
source share