astrofrog / mpl-scatter-density

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

Adaptable density vmin/vmax functions #23

Closed samverstocken closed 5 years ago

samverstocken commented 5 years ago

I propose a small change, where the constructor of the GenericDensityArtist accepts the 'density_vmin', and 'density_vmax' arguments. These then set:

self._density_vmin = density_vmin
self._density_vmax = density_vmax

they have the default values of np.nanmin and np.nanmax, as is hardcoded at the moment.

I, for example, pass the following values for vmin and vmax:

density_vmin = 0
density_vmax = vmax_function

where:

def vmax_function(array):
    from astropy.stats import sigma_clip
    masked_array = sigma_clip(array[array != 0], sigma=4.0)
    values = masked_array.compressed()
    return np.nanmax(values)

I did this because some datasets were invisible with the standard min and max interval, perhaps because of outliers in the density.

astrofrog commented 5 years ago

@samverstocken - just to check, are you suggesting we change the default functions? Currently it's already acceptable to set vmin/vmax to either scalars or functions. Maybe this should be documented in the README though, with an example like the one you have.

samverstocken commented 5 years ago

@astrofrog I'm sorry, I did not realize these functions could also just be passed to the vmin and vmax arguments