Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib + Seaborn - two lines with the same color?

I'm stuck on what is likely a simple thing. I'm using the default seaborn color palette in Matplotlib. I want to plot two lines that have the same color AND I want to define that color. I would like to use the colors that are part of the default seaborn palette, i.e. I'd like the seaborn red instead of the Matplotlib default red.

Here's 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 above code, I get Matplotlib's default red (as expected). Is there any "easy" way to tell it seaborn's red? If I don't define the colors, the colors will cycle through seaborn's default color cycle. Thanks!

like image 945
Ryan James Avatar asked Nov 04 '15 05:11

Ryan James


People also ask

How do I change my line color in seaborn?

So by setting color = 'red' , we're telling the Seaborn Objects system to change the color of the line to red. Note also that you can use any “named color” that Python recognizes.

What does SNS Lineplot do?

Draw a line plot with possibility of several semantic groupings. The relationship between x and y can be shown for different subsets of the data using the hue , size , and style parameters. These parameters control what visual semantics are used to identify the different subsets.

What is the use of CMAP in seaborn?

You can customize the colors in your heatmap with the cmap parameter of the heatmap() function in seaborn. The following examples show the appearences of different sequential color palettes.


1 Answers

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

like image 124
mwaskom Avatar answered Sep 18 '22 12:09

mwaskom