J Doe
J Doe

Reputation: 359

Seaborn line across scatterplot

I have a seaborn scatterplot across categories (y-axis) with time on the x-axis:

z=sns.scatterplot(data=df], x="transaction_date", y="product_name", hue="source_of_business",s=100)

What's the best way to add a line across each date category combination like below

Upvotes: 0

Views: 111

Answers (1)

r-beginners
r-beginners

Reputation: 35155

This can be done by setting up a line chart using data frames extracted by product name.

ax = sns.scatterplot(data=df, x="transaction_date", y="product_name", hue="source_of_business", s=100)
for c in df['product_name'].unique():
    dfq = df.query('product_name == @c').reset_index()
    sns.lineplot(data=dfq, x='transaction_date',y='product_name', color='black', ax=ax) 

enter image description here

Upvotes: 1

Related Questions