Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seaborn scatterplot scale bubble size to larger dots

I am following this example and I want to create larger bubbles but no matter how big I multiply the size column they are still tiny, is there some sort of scaling factor to adjust? I can't find it in the documentation.

import seaborn as sns; sns.set()
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
ax = sns.scatterplot(x="total_bill", y="tip", data=tips)

cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
ax = sns.scatterplot(x="total_bill", y="tip",
                     hue="size", size="size",
                     palette=cmap,
                     data=tips)

enter image description here

tips['size'] = 100 * tips['size']

ax = sns.scatterplot(x="total_bill", y="tip",
                     hue="size", size="size",
                     palette=cmap,
                     data=tips)

enter image description here

Example code here

like image 826
user2471214 Avatar asked Sep 08 '26 22:09

user2471214


2 Answers

Apparently, you also need to use the sizes parameter in seaborn.scatterplot to achieve specified size range.

minsize = min(tips['size'])
maxsize = max(tips['size'])
ax = sns.scatterplot(x="total_bill", y="tip",
                    hue="size", size="size", sizes=(minsize, maxsize),
                    palette=cmap,
                    data=tips)

enter image description here

like image 118
SKPS Avatar answered Sep 10 '26 12:09

SKPS


Thx for this method! it works great. I had the same issue when setting big size fig with a lot of data. scatter appeared so tiny I couldn't distinguish the size. so first set the tupple, the inject it into sns.scatter

btw, with this method you can play on minsize and maxsize with a multpiply factor without changing the actual data of size and thus the legend. I had to put minsize and maxsize to fifth power to make it readable! thank you so much!

minsize = min(df['value'])**5
maxsize = max(df['value'])**5
fx= sns.scatterplot(x=df['this'], y=df['that'], data=df, hue=df['takeway'], size=df['value'], sizes=(minsize, maxsize), legend='brief')
like image 23
polo Avatar answered Sep 10 '26 12:09

polo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!