plot_distribution#

gammapy.visualization.plot_distribution(wcs_map, ax=None, ncols=3, func=None, kwargs_hist=None, kwargs_axes=None, kwargs_fit=None)[source]#

Plot the 1D distribution of data inside a map as an histogram. If the dimension of the map is smaller than 2, a unique plot will be displayed. Otherwise, if the dimension is 3 or greater, a grid of plot will be displayed.

Parameters
wcs_mapWcsNDMap

A map that contains data to be plotted.

axAxes or list of Axes

Axis object to plot on. If a list of Axis is provided it has to be the same length as the length of _map.data.

ncolsint

Number of columns to plot if a “plot grid” was to be done.

funcfunction object or str

The function used to fit a map data histogram or “norm”. Default is None. If None, no fit will be performed. If “norm” is given, scipy.stats.norm.pdf will be passed to scipy.optimize.curve_fit.

kwargs_histdict

Keyword arguments to pass to matplotlib.pyplot.hist.

kwargs_axesdict

Keyword arguments to pass to matplotlib.axes.Axes.

kwargs_fitdict

Keyword arguments to pass to scipy.optimize.curve_fit

Returns
axesndarray of Axes

Array of Axes.

result_listlist of dict

List of dictionnary that contains the results of scipy.optimize.curve_fit. The number of elements in the list correspond to the dimension of the non-spatial axis of the map. The dictionnary contains:

  • axis_edges : the edges of the non-spatial axis bin used

  • param : the best-fit parameters of the input function func

  • covar : the covariance matrix for the fitted parameters param

  • info_dict : the infodict return of scipy.optimize.curve_fit

Examples

>>> from gammapy.datasets import MapDataset
>>> from gammapy.estimators import TSMapEstimator
>>> from scipy.stats import norm
>>> from gammapy.visualization import plot_distribution
>>> dataset = MapDataset.read("$GAMMAPY_DATA/cta-1dc-gc/cta-1dc-gc.fits.gz")
>>> tsmap_est = TSMapEstimator().run(dataset)
>>> axs, res = plot_distribution(tsmap_est.sqrt_ts, func="norm", kwargs_hist={'bins': 75, 'range': (-10, 10), 'density': True})
>>> # Equivalently, one can do the following:
>>> func = lambda x, mu, sig : norm.pdf(x, loc=mu, scale=sig)
>>> axs, res = plot_distribution(tsmap_est.sqrt_ts, func=func, kwargs_hist={'bins': 75, 'range': (-10, 10), 'density': True})