Is there someway to create a bubble plot with seaborn? I already know how to do it with Matplot lib, as in this tutorial.

# libraries
import matplotlib.pyplot as plt
import numpy as np
# create data
x = np.random.rand(40)
y = np.random.rand(40)
z = np.random.rand(40)
# use the scatter function
plt.scatter(x, y, s=z*1000, alpha=0.5)

I would like to replicate this with Seaborn. I am able to plot, but cannot control the size of marker.

import seaborn as sns
import numpy as np
%matplotlib inline
data=pd.DataFrame({"x":x, "y":y,"z":z})
sns.lmplot(x="x", y="y",data=data,  fit_reg=False)

A duplicate of this question in stackoverflow. Anyhow just to recap quickly, you can do it with:

scatter_kws={"s": 10}

And in your case it is simply:

sns.lmplot(x="x", y="y",data=data,  fit_reg=False,scatter_kws={"s": z*1000})
  • $\begingroup$ Sorry I missed the original question, this works great! $\endgroup$ – user61034 May 16 '18 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.