1

I need to colour all line graphs in a different grey, using one of Seaborn's greyscale, like binary. One line (2022), however, needs to be orange.

This is what I currently have: enter image description here

This is what my code looks like, I have not been able to get a grey colour palette to work in there:

palette = {year:'orange' if year == 2022 else 'gray' for year in df.year.unique()}

sns.set(rc = {'figure.figsize':(12, 8)})
ax = sns.lineplot(x = 'week' 
                  , y = 'Deduplication Ratio' 
                  , hue = 'year' 
                  , ci = None
                  , data = df
                  , palette = palette
                  )

I would like the data to look like this though: Excel data viz with 1 orange line, and 3 lines in different greys.

Would anyone know how I can display the grey lines in different greys?

PS: I have to replicate this task multiple times where there will be more than just 4 years. So doing this manually will not be an option.

Lucas
  • 17
  • 6

1 Answers1

2

Maybe something like this:

years = sorted(df["year"].unique())
greys = iter(sns.color_palette("Greys", len(years)))
palette = {year: 'orange' if year == 2022 else next(greys) for year in years}
mwaskom
  • 46,693
  • 16
  • 125
  • 127
  • This worked a charm, thanks so much, @mwaskom. The slide already looks much clearer. Would you know how I could make the orange (only) line bold? – Lucas Nov 03 '22 at 16:43
  • Same idea but with `size` and `sizes`. – mwaskom Nov 04 '22 at 00:08
  • I didn't get it to work, unfortunately. Would that be smth like this? `size_df = iter(sns.color_palette("binary", len(years))) sizes = {year: 10 if year == 2022 else next(size_df) for year in years}` and then do `sns.lineplot(…  , linewidth = sizes )` – Lucas Nov 15 '22 at 13:32