pythonseabornvisualizationlinegraph

Make all line graphs grey using grey scale, apart from one coloured line in Seaborn


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.


Solution

  • 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}