threeML.io.plotting package

Submodules

threeML.io.plotting.cmap_cycle module

threeML.io.plotting.cmap_cycle.cmap_intervals(length=50, cmap='YlOrBr', start=None, stop=None)[source]

Return evenly spaced intervals of a given colormap cmap.

Colormaps listed in REVERSE_CMAP will be cycled in reverse order. Certain colormaps have pre-specified color ranges in CMAP_RANGE. These module variables ensure that colors cycle from light to dark and light colors are not too close to white.

Parameters

length – int the number of colors used before cycling back to first color. When

length is large (> ~10), it is difficult to distinguish between successive lines because successive colors are very similar. :param cmap: str name of a matplotlib colormap (see matplotlib.pyplot.cm)

threeML.io.plotting.data_residual_plot module

class threeML.io.plotting.data_residual_plot.ResidualPlot(**kwargs)[source]

Bases: object

add_data(x, y, residuals, label, xerr=None, yerr=None, residual_yerr=None, show_data=True, **kwargs)[source]

Add the data for the this model

Parameters
  • x – energy of the data

  • y – value of the data

  • residuals – the residuals for the data

  • label – label of the data

  • xerr – the error in energy (or bin width)

  • yerr – the errorbars of the data

  • **kwargs

    any kwargs passed to plot

Returns

add_model(x, y, label, **kwargs)[source]

Add a model and interpolate it across the energy span for the plotting.

Parameters
  • x – the evaluation energies

  • y – the model values

  • label – the label of the model

  • **kwargs

    any kwargs passed to plot

Returns

None

add_model_step(xmin, xmax, xwidth, y, label, **kwargs)[source]

Add a model but use discontinuous steps for the plotting.

Parameters
  • xmin – the low end boundaries

  • xmax – the high end boundaries

  • xwidth – the width of the bins

  • y – the height of the bins

  • label – the label of the model

  • **kwargs

    any kwargs passed to plot

Returns

None

property data_axis
Returns

the top or data axis

property figure
Returns

the figure instance

finalize(xlabel='x', ylabel='y', xscale='log', yscale='log', show_legend=True, invert_y=False)[source]
Parameters
  • xlabel

  • ylabel

  • xscale

  • yscale

  • show_legend

Returns

property ratio_residuals
property residual_axis
Returns

the bottom or residual axis

property show_residuals

threeML.io.plotting.light_curve_plots module

threeML.io.plotting.light_curve_plots.binned_light_curve_plot(time_bins, cnts, width, bkg=None, selection=None, bkg_selections=None)[source]
Parameters
  • time_bins – stacked array of time intervals

  • cnts – counts per bin

  • bkg – background of the light curve

  • width – with of the bins

  • selection – bin selection

  • bkg_selections

  • instrument

Returns

threeML.io.plotting.light_curve_plots.channel_plot(ax, chan_min, chan_max, counts, **kwargs)[source]
threeML.io.plotting.light_curve_plots.disjoint_patch_plot(ax: matplotlib.axes._axes.Axes, bin_min: numpy.array, bin_max: numpy.array, top: float, bottom: float, mask: numpy.array, **kwargs: dict) → None[source]

plots patches that are disjoint given by the mask

Parameters
  • ax – matplotlib Axes to plot to

  • bin_min – bin starts

  • bin_max – bin stops

  • top – top y value to plot

  • bottom – bottom y value to plot

  • mask – mask of the bins

  • kwargs – matplotlib plot keywords

Returns

threeML.io.plotting.light_curve_plots.plot_tte_lightcurve(tte_file: str, start: float = - 10, stop: float = 50, dt: float = 1) → matplotlib.figure.Figure[source]

quick plot of a TTE light curve :param tte_file: GBM TTE file name :param start: start of the light curve :param stop: stop of the light curve :param dt: with of the bins

threeML.io.plotting.light_curve_plots.slice_disjoint(arr)[source]

Returns an array of disjoint indices from a bool array

Parameters

arr – and array of bools

threeML.io.plotting.model_plot module

class threeML.io.plotting.model_plot.SpectralContourPlot(n_total, xscale='log', yscale='log', show_legend=True, plot_kwargs=None, contour_kwargs=None, legend_kwargs=None, emin=None, emax=None, subplot=None)[source]

Bases: object

add_dimensionless_model(energy_range, best_fit, color, upper_error=None, lower_error=None, contour_color=None, label='model')[source]
add_model(energy_range, best_fit, color, upper_error=None, lower_error=None, contour_color=None, label='model')[source]
finalize(_defaults)[source]
threeML.io.plotting.model_plot.plot_point_source_spectra(*analysis_results, **kwargs)[source]
threeML.io.plotting.model_plot.plot_spectra(*analysis_results, **kwargs)[source]

plotting routine for fitted point source spectra

Parameters
  • analysis_results – fitted JointLikelihood or BayesianAnalysis objects

  • sources_to_use – (optional) list of PointSource string names to plot from the analysis

  • energy_unit – (optional) astropy energy unit in string form (can also be frequency)

  • flux_unit – (optional) astropy flux unit in string form

  • confidence_level – (optional) confidence level to use (default: 0.68)

  • ene_min – (optional) minimum energy to plot

  • ene_max – (optional) maximum energy to plot

  • num_ene – (optional) number of energies to plot

  • use_components – (optional) True or False to plot the spectral components

  • components_to_use – (optional) list of string names of the components to plot: including ‘total’

will also plot the total spectrum :param sum_sources: (optional) some all the MLE and Bayesian sources :param show_contours: (optional) True or False to plot the contour region :param plot_style_kwargs: (optional) dictionary of MPL plot styling for the best fit curve :param contour_style_kwargs: (optional) dictionary of MPL plot styling for the contour regions :param fit_cmap: MPL color map to iterate over for plotting multiple analyses :param contour_cmap: MPL color map to iterate over for plotting contours for multiple analyses :param subplot: subplot to use :param xscale: ‘log’ or ‘linear’ :param yscale: ‘log’ or ‘linear’ :param include_extended: True or False, also plot extended source spectra. :return:

threeML.io.plotting.plot_style module

class threeML.io.plotting.plot_style.PlotStyle(matplotlib_base_style='seaborn-notebook', matplotlib_overrides=None, threeml_style=None)[source]

Bases: object

Contains the styles for the plots. It embeds the matplotlib style, so that by choosing an instance of PlotStyle the user can set at the same time the matplotlib style and all the elements of the 3ML style.

activate()[source]

Activate this style so that it becomes the default style for any plot. This is mainly useful for the default style. For any other style, use the with plot_style([style name]) context manager instead.

Returns

None

clone()[source]

Clone this style

static deactivate()[source]

Deactivate the current style and restore the default. Do not use this directly. Use the with plot_style([style name]) context manager instead.

Returns

None

classmethod from_style_file(filename)[source]
save(name, overwrite=False)[source]

Save the style with the provided name, so it will be made available also in future sessions of 3ML.

Parameters
  • name – the name to give to the new style

  • overwrite – whether to overwrite an existing style with the same name or not

Returns

the path of the YAML file in which the style has been saved for future use

threeML.io.plotting.plot_style.create_new_plotting_style(based_on='default')[source]

Create a new plotting style ready for customization, based on an existing plotting style. By default, the default plotting style is used.

Parameters

based_on – the plot style to clone. By default, the default plotting style is used.

Returns

a PlotStyle instance ready for customization

threeML.io.plotting.plot_style.get_available_plotting_styles()[source]
threeML.io.plotting.plot_style.plot_style(style_name)[source]

A context manager to temporarily change the plotting style to the provided style.

Examples:

Say we have defined a style ‘plain’:

with plot_style('plain'):

    # plots generated here will have the 'plain' style

    ...

# plots generated here will have the default style
...

You can also temporarily change an attribute of the style within the with context:

with plot_style('plain') as my_style:

    # Temporarily change the width of the lines. Outside of this particular "with" context
    # reusing the "plain" style will result in normal lines

    my_style['lines.linewidth'] = 2

    # plots generated here will have the 'plain' style with lines with double width

# Plots generated here will have the default style

...
Parameters

style_name – name of the style. Use get_available_plotting_styles() to get a list of known styles.

Returns

style instance

threeML.io.plotting.post_process_data_plots module

threeML.io.plotting.post_process_data_plots.display_photometry_model_magnitudes(analysis, data=(), **kwargs)[source]

Display the fitted model count spectrum of one or more Spectrum plugins

NOTE: all parameters passed as keyword arguments that are not in the list below, will be passed as keyword arguments to the plt.subplots() constructor. So for example, you can specify the size of the figure using figsize = (20,10)

Parameters
  • args – one or more instances of Spectrum plugin

  • min_rate – (optional) rebin to keep this minimum rate in each channel (if possible). If one number is

provided, the same minimum rate is used for each dataset, otherwise a list can be provided with the minimum rate for each dataset :param data_cmap: (str) (optional) the color map used to extract automatically the colors for the data :param model_cmap: (str) (optional) the color map used to extract automatically the colors for the models :param data_colors: (optional) a tuple or list with the color for each dataset :param model_colors: (optional) a tuple or list with the color for each folded model :param show_legend: (optional) if True (default), shows a legend :param step: (optional) if True (default), show the folded model as steps, if False, the folded model is plotted with linear interpolation between each bin :return: figure instance

threeML.io.plotting.post_process_data_plots.display_spectrum_model_counts(analysis, data=(), **kwargs)[source]

Display the fitted model count spectrum of one or more Spectrum plugins

NOTE: all parameters passed as keyword arguments that are not in the list below, will be passed as keyword arguments to the plt.subplots() constructor. So for example, you can specify the size of the figure using figsize = (20,10)

Parameters
  • args – one or more instances of Spectrum plugin

  • min_rate – (optional) rebin to keep this minimum rate in each channel (if possible). If one number is

provided, the same minimum rate is used for each dataset, otherwise a list can be provided with the minimum rate for each dataset :param data_cmap: (str) (optional) the color map used to extract automatically the colors for the data :param model_cmap: (str) (optional) the color map used to extract automatically the colors for the models :param data_colors: (optional) a tuple or list with the color for each dataset :param model_colors: (optional) a tuple or list with the color for each folded model :param data_color: (optional) color for all datasets :param model_color: (optional) color for all folded models :param show_legend: (optional) if True (default), shows a legend :param step: (optional) if True (default), show the folded model as steps, if False, the folded model is plotted :param model_subplot: (optional) axe(s) to plot to for overplotting with linear interpolation between each bin :param data_per_plot: (optional) Can spezify how many detectors should be plotted in one plot. If there are more detectors than this number it will split it up in several plots :param show_background: (optional) Also show the background :param source_only: (optional) Plot only source (total data - background) :param background_cmap: (str) (optional) the color map used to extract automatically the colors for the background :param background_colors: (optional) a tuple or list with the color for each background :param background_color: (optional) color for all backgrounds :return: figure instance

threeML.io.plotting.step_plot module

threeML.io.plotting.step_plot.step_plot(xbins, y, ax, fill=False, fill_min=0, **kwargs)[source]

Routine for plotting a in steps with the ability to fill the plot xbins is a 2D list of start and stop values. y are the values in the bins.

Module contents