Matplotlib + Seaborn - two lines of the same color?

I am stuck in what is probably simple. I use the standard color palette in Matplotlib. I want to build two lines having the same color. I want to define this color. I would like to use colors that are part of the default palette, i.e. I would like red blue instead of red by default Matplotlib.

Here is my code snippet:

import pylab as plot import seaborn t = np.arange(0.0, 2.0, 0.01) s = np.sin(2*np.pi*t) plt.plot(t, s, 'r') plt.plot(t, 2*s, 'r') 

If I use the code above, I get the default red font Matplotlib (as expected). Is there any β€œsimple” way of saying that it is red? If I do not define colors, the colors will cycle through the default blue color. Thanks!

+5
source share
2 answers

You can get sea colors by default using seaborn.color_palette() (there are several different palettes that you can get through this function). So you can do:

 t = np.arange(0.0, 2.0, 0.01) s = np.sin(2*np.pi*t) plt.plot(t, s, c=seaborn.color_palette()[2]) plt.plot(t, 2*s, c=seaborn.color_palette()[2]) 

You need to go through the default palette yourself and determine which value matches the color, there are no useful names, such as "red" attached to the RBG values, from what I saw.

+7
source

On the seashore 0.6 or later, you can call seaborn.set_color_codes() or seaborn.set(color_codes=True) , and "r" will be interpreted as red blue by default.

+7
source

Source: https://habr.com/ru/post/1235168/


All Articles