mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.59k stars 1.93k forks source link

Cannot plot certain data with kdeplot, warning that dataset has 0 variance which is not. #3749

Closed Wongboo closed 3 months ago

Wongboo commented 3 months ago

Cannot plot certain data with kdeplot, warning that dataset has 0 variance which is not.

/gpfs/share/code/pku_env/micromamba/envs/pytorch_cpu/lib/python3.12/site-packages/pandas/core/nanops.py:1016: RuntimeWarning: invalid value encountered in subtract
  sqr = _ensure_numeric((avg - values) ** 2)
<ipython-input-20-d1f90ecbf4e4>:1: UserWarning: Dataset has 0 variance; skipping density estimate. Pass `warn_singular=False` to disable this warning.
  sns.kdeplot(s, bw_adjust=.25, log_scale=True)

Checking dataset

In [32]: print(s.mean(), s.std(), s.max(), s.min())
7.094745e-11 2.368824e-10 1.5460646e-08 0.0

disable log_scale or use a fraction of sample such as s[10000:] does no help. dataset npy zipped file exp2.zip

mwaskom commented 3 months ago

Variance may not be literally zero while still close enough for density estimation to fail. You could try changing the scale of your data perhaps.