Search code examples
pythoncolorsseabornscatter-plot

How do I use the "next" color in the palette without specifying it manually?


I am drawing a few scatter plots in seaborn and they all come out with blue points:

enter image description here

I would like to change the color of the points. I found some rather complicated solutions where you can specify the color manually, but this is not what I want.

I don't care which color it is, it should just be different from blue and be one of the colors of the current palette to keep the visuals pleasing.

Is there something like start_with_palette_color=1 (default 0) in:

sns.scatterplot(data=tips, x="total_bill", y="tip", start_with_palette_color=1)

?


Solution

  • The current palette can be viewed with color_palette() when called without parameters. It returns a list of RGB tuples that represent the palette's colors.

    scatterplot() accepts the named parameter color= to specify any color.

    import seaborn as sns
    tips = sns.load_dataset("tips")
    # first scatter plot with default color
    sns.scatterplot(data=tips, x="total_bill", y="tip")
    # second scatter plot with the next color (array index 1 instead of implicit 0)
    sns.scatterplot(data=tips, x="total_bill", y="tip",color=sns.color_palette()[1])