Define Color and Marker for each category specifically

Viewed 40

I am plotting some scatter plots, which are "temperature x element", and I want to set the legend to match two other parameters.

The thing is: I want to define the symbol and colour for each parameter so that all my legends have the same legends always.

For example: Parameter 1 - Location France: squares. Portugal: circles. Spain: triangles.

I have plot this:

sns.set_style("ticks")
sns.set_context("paper")
sns.relplot(data=bt, x="T", y="Li", hue="minerals", style="Location", palette="dark") 
plt.title("Li vs T")
plt.xlabel("T (°C)")
plt.ylabel("Li (ppm)")

enter image description here

However, the markers and colours are defined automatically, but I want to edit each category individually.

1 Answers

Seaborn's relplot passes keyword arguments down to the axes-level plot, in this case scatterplot (the default relplot). The scatterplot docs explain that you can use the markers argument with a list or dictionary of markers, eg markers={'France': 's', 'Portugal': 'o', 'Spain': '^'}. Valid markers in Matplotlib scatter charts are defined here. So:

sns.relplot(data=bt, x="T", y="Li", hue="minerals", style="Location",
           palette="dark", markers={'France': 's', 'Portugal': 'o', 'Spain': '^'})
Related