0

I am trying to add another dimension to a seaborn swarmplot such that the extra dimension is marked by a unique marker. I already have the hue set to a column in the dataframe, but I'm at a loss as for how I can add another way of distinguishing certain information. Every data point in the plot has an associated "heat number" and I'm trying to assign a unique marker to each heat number.

I came across this answer (swarmplot with hue affecting marker beyond color) and it's close to what I'm trying, but I think my case is more complicated since I'm trying to assign markers based on a different category.

Here's my code so far (the data values are not real but gives an example):


fig, a = plt.subplots(dpi = 150)

c_data = [10,20,30,35, 8]
time_data = [100, 1000, 10000, 4000, 16000]
gs_data = [1.5, 2, 3, 4, 5]
heat_data = [2412, 1421, 1445, 6366, 1131]

df['charpy'] = c_data
df['time'] = time_data 
df['Grain Size'] = gs_data
df['Heat'] = heat_data
sns.swarmplot(data = df, x = 'time', y = 'charpy', hue = 'Grain Size', ax = a, size = 8)

It's very simple at this point because I'm honestly not sure what my next steps, and the other examples I've looked up can't really be applied to my case. Any help is appreciated.

My swarmplot with multiple times as x-axis, and grain size as the hue.

Austin
  • 43
  • 1
  • 5

1 Answers1

1

It's not currently possible (without pain) with swarmplot. However, if you use scatterplot, you can add a second "category" with style parameter.

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
ax = sns.scatterplot(data=tips, x='day', y='total_bill', hue='sex', style='smoker')
plt.show()

Output:

enter image description here

Seaborn provides the seaborn.categorical.Beeswarm class to compute offsets from points. Maybe you can ask the author how to use it from a scatterplot.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Corralien
  • 109,409
  • 8
  • 28
  • 52