title: Recurring Custom Color Palette for Seaborn/Python/Matplotlib
body: <p>I am looking to see if there is a way to set up a color palette to make sure that any time I graph, the colors of the bars will be consistent with the values on the x axis.</p>
  
  <p>I am using Seaborn</p>
  
  <p>I'm sure this is somewhere online, but have been searching for over an hour with no luck</p>
  
  <p>For example, I would want:</p>
  
  <p>"Thursday" to always map to purple,
     "Friday" to always map to red,
     "Saturday" to always map to green,
     "Sunday" to always map to blue,</p>
  
  <p>I will be using this for a variety of different charts, using different criteria - sometimes all 4 days will be included, sometimes they won't be</p>
  
  <p>If you look at the example below, the colors work fine</p>
  
  <p>Example 1:</p>
  
  <pre><code>%matplotlib inline
  import pandas as pd
  import seaborn as sns
  df=pd.read_csv("https://raw.githubusercontent.com/wesm/pydata-   book/master/ch08/tips.csv", sep=',')
  df=df[(df['sex']=='Female')&amp;(df['smoker']=='No')&amp;(df['time']=='Dinner')&amp;(df['size']==2)]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/IO8nt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IO8nt.png" alt="Looks as follows"></a></p>
  
  <p>But Example 2 , based on the filtering out of Sunday:</p>
  
  <pre><code>%matplotlib inline
  import pandas as pd
  import seaborn as sns
  df=pd.read_csv("https://raw.githubusercontent.com/wesm/pydata-   book/master/ch08/tips.csv", sep=',')
  df=df[(df['sex']=='Female')&amp;(df['smoker']=='No')&amp;(df['time']=='Dinner')&amp;(df['size']==2)]
  df=df[df['day']!='Sun']
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CjH7x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CjH7x.png" alt="Looks as Follows"></a></p>
  
  <p>Well, notice how all of the colors shifted</p>
  
  <p>How do I set up a custom Palette that gets mapped to a master list of values (i.e. Monday = Red, Tuesday=Green, Wednesday=Blue, etc).  Dynamically would be great, but static list is ok also</p>
  
  <p>I know I can do something like:</p>
  
  <pre><code>pal = dict(Sat="k", Thur="b", Fri="y", Sun="#9b59b6")
  
  x=sns.barplot(x="day",y="tip",data=df, palette=pal)
  </code></pre>
  
  <p>Which sets up a palette and then applies it to each bar, but I was more hoping to be able to use an existing palette, something like</p>
  
  <pre><code>sns.color_palette("Set1", n_colors=30, desat=.5)
  </code></pre>
  
  <p>And then iterate through the palette and assign each color to a value (i.e. first value is monday, second tuesday, etc)</p>
  
  <p>Would appreciate any help!</p>
  
  <p>Thank you!</p>
  
  <p>Jeff</p>