Using different colors and shapes in a legend [Seaborn, Python]

I have read examples on how to use different shapes and / or colors to separate data in a Seaborn plot. However, it seems that the color and the shapes are linked together to show a separate variable. For example, in the following script (borrowed from the link above) it seems like you can only use green arrows and gray up arrows:

g = sns.FacetGrid(tips, col="sex", hue="time", palette=pal,
                  hue_order=["Dinner", "Lunch"],
                  hue_kws=dict(marker=["^", "v"]))
g = (, "total_bill", "tip", **kws).add_legend())


Is it possible to show, say, green arrows and gray arrows, as well as green arrows and gray down arrows?

I've tried defining a dictionary for in a col

similar way to what is being done for hue

, but I'm still trying to wrap the topic around myself.


source to share

1 answer

I assume that you will use some of the functions of the function sns.FacetGrid

. If you're just trying to make a simple scatter plot, then using it plt.scatter

directly is probably more straight forward.

In any case, it is possible to use any colors and symbols that you want to use in the FacetGrid example. I'm not a Seaborn pro, but here's one way to achieve this:

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
kws = dict(s=50, linewidth=.5, edgecolor="w")
pal = ['red', 'green', 'blue', 'red', 'green', 'blue',]
g = sns.FacetGrid(tips, col="sex", hue="size", palette=pal, hue_kws=dict(marker=["^", "^", "^", "v", "v", "v"]))
g = (, "total_bill", "tip", **kws).add_legend())


example output



All Articles