astrofrog / mpl-scatter-density

:zap: Fast scatter density plots for Matplotlib :zap:
BSD 2-Clause "Simplified" License
498 stars 25 forks source link

Spurious(?) all-NaN slice RuntimeWarning #35

Open anntzer opened 3 years ago

anntzer commented 3 years ago

For example, the first example given in the README (using the 'scatter_density' method) currently emits

.../lib/python3.9/site-packages/mpl_scatter_density/generic_density_artist.py:77: RuntimeWarning: All-NaN slice encountered
  vmin = self._density_vmin(array)
.../lib/python3.9/site-packages/mpl_scatter_density/generic_density_artist.py:82: RuntimeWarning: All-NaN slice encountered
  vmax = self._density_vmax(array)

when run with numpy 1.20.1, matplotlib 3.3.0, mpl-scatter-density 0.7.

wphilips commented 3 years ago

The issue is caused by the call self.set_array(EMPTY_IMAGE) in base_image_artist.py(70); EMPTY_IMAGE is an array with a single Nan entry At some point this calls vmin = self._density_vmin(array) in generic_density_artist.py(77) and this generates the warning.

I hope it can be fixed.

ba05 commented 11 months ago

Any fix?

ba05 commented 8 months ago

This is a numpy issue occuring in numpy\lib\nanfunctions.py https://github.com/numpy/numpy/blob/v1.26.0/numpy/lib/nanfunctions.py#L236-L361

Can suppress the warning by wrapping the code section causing the warning with a warning ignore statement. See this post: https://stackoverflow.com/questions/29688168/mean-nanmean-and-warning-mean-of-empty-slice