This code is provided in the book "Pandas for everyone" (3.4.3.2 Size and Shape).
import seaborn as sns
from matplotlib import pyplot as plt
tips = sns.load_dataset('tips')
sns.lmplot(
x='total_bill',
y='tip',
data=tips,
fit_reg=False,
hue='sex',
scatter_kws={'s': tips['size'] * 10}
)
plt.show()
When I run this code, it results ValueError at matplotlib/axes/_axes.py line 4508.
ValueError: s must be a scalar, or float array-like with the same size as x and y
This error won't be raised if I omit the hue
argument. It seems that the data (tips['total_bill']
and tips['tip']
) are split by sex
, but tips['size']
is not split, so the lengths are different.
How can I manage to plot the figure without error?
Versions
- Python 3.7
- matplotlib 3.4.2
- seaborn 0.11.1
Ran on both windows 10 and Google Colab.