pythonseaborn

Change marker type depending on dataframe value on seaborn jointplot


Using below code

import seaborn as sns
penguins = sns.load_dataset('penguins')

markers = (['x','o','v'])
sns.jointplot(data=penguins, x="flipper_length_mm", y="bill_length_mm",
              hue="species", height=10)

I would like to change marker depending on the "species" group. Tried

sns.jointplot(data=penguins, x="flipper_length_mm", y="bill_length_mm",
              hue="species", height=10, joint_kws={"marker": markers})

as suggested in another post but got

ValueError: Unrecognized marker style ['x', 'o', 'v']

Any hints?


Solution

  • You can't, jointplot doesn't support different markers. However scatterplot does. Use a JointGrid and plot your scatterplot manually:

    import seaborn as sns
    
    penguins = sns.load_dataset('penguins')
    markers = ['x', 'o', 'v']
    
    g = sns.JointGrid(data=penguins, x='flipper_length_mm', y='bill_length_mm',
                      hue='species', height=5)
    sns.scatterplot(data=penguins, x='flipper_length_mm', y='bill_length_mm',
                    hue='species', style='species', ax=g.ax_joint)
    g.plot_marginals(sns.kdeplot, fill=True)
    

    Output:

    enter image description here