0

I'm trying to dynamically label all datapoints in a Seaborn catplot. Reproducible code here:

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sns

data = [['Vestibulum', 1, 'Augusti', 189],
        ['Quam', 1, 'Augusti', 207],
        ['Dolor', 1, 'Augusti', 220],
        ['Posuere', 1, 'Augusti', 231],
        ['Vitae', 2, 'Legionis', 239],
        ['Amet', 2, 'Legionis', 289],
        ['Ullamcorper', 2, 'Legionis', 302],
        ['Fusce', 3, 'Tribunus', 289],
        ['', 4, 'Praefectus', ],
        ['Suscipit', 5, 'Tribuni', 376],
        ['', 6, 'Angusticlavi', ]]
  
df = pd.DataFrame(data, columns = ['name', 'order', 'role', 'aureus'])

df

enter image description here

I've got the basic catplot I'm looking for here, sans labels:

sns.set(style='whitegrid')

sns.catplot(x="role",
            y="aureus",
            data=df, 
            jitter='0', 
            s=15)

plt.gcf().set_size_inches(25, 12)
plt.ylim(0, 500)

And here's the resulting plot: enter image description here

This is dummy data, and the values will change (x-axis categories, y-axis, etc.), although the absolute number of data points will stay the same. I'd like to do this dynamically based on the data, and not get overly specific with plotting individual annotations. I'm looking to add data labels for each datapoint, to the right, based on values in the 'name' column of the dataframe.

Appreciate any pointers here!

MStu
  • 31
  • 1
  • 3

0 Answers0