physt.plotting package

Submodules

physt.plotting.vega module

Vega3 backend for plotting in physt.

The JSON can be produced without any external dependency, the ability to show plots in-line in IPython requires ‘vega3’ library.

Implementation note: Values passed to JSON cannot be of type np.int64 (solution: explicit cast to float)

Common parameters

See the enable_inline_view wrapper.

physt.plotting.vega.bar(h1, **kwargs)

Bar plot of 1D histogram.

Parameters:
  • h1 (physt.histogram1d.Histogram1D) – Dimensionality of histogram for which it is applicable
  • lw (float) – Width of the line between bars
  • alpha (float) – Opacity of the bars
  • hover_alpha (float) – Opacity of the bars when hover on
physt.plotting.vega.display_vega(vega_data, display=True)

Optionally display vega dictionary.

Parameters:
  • vega_data (dict) – Valid vega data as dictionary
  • display (True | False) – Whether to try in-line display in IPython
physt.plotting.vega.enable_inline_view(f)

Decorator to enable in-line viewing in Python and saving to external file.

It adds several parameters to each decorated plotted function:

Parameters:
  • write_to (str (optional)) – Path to write vega JSON/HTML to.
  • write_format ("auto" | "json" | "html") – Whether to create a JSON data file or a full-fledged HTML page.
  • display ("auto" | True | False) – Whether to try in-line display in IPython
  • indent (int) – Indentation of JSON
physt.plotting.vega.line(h1, **kwargs)

Line plot of 1D histogram values.

Points are horizontally placed in bin centers.

Parameters:h1 (physt.histogram1d.Histogram1D) – Dimensionality of histogram for which it is applicable
physt.plotting.vega.map(h2, show_zero=True, show_values=False, **kwargs)

Heat-map of two-dimensional histogram.

Parameters:
physt.plotting.vega.map_with_slider(h3, show_zero=True, show_values=False, **kwargs)

Heatmap showing slice in first two dimensions, third dimension represented as a slider.

Parameters:
physt.plotting.vega.scatter(h1, **kwargs)

Scatter plot of 1D histogram values.

Points are horizontally placed in bin centers.

Parameters:h1 (physt.histogram1d.Histogram1D) – Dimensionality of histogram for which it is applicable
physt.plotting.vega.write_vega(vega_data, title, write_to, write_format='auto', indent=2)

Write vega dictionary to an external file.

Parameters:
  • vega_data (dict) – Valid vega data as dictionary
  • write_to (str (optional)) – Path to write vega JSON/HTML to.
  • write_format ("auto" | "json" | "html") – Whether to create a JSON data file or a full-fledged HTML page.
  • indent (int) – Indentation of JSON

physt.plotting.common module

Functions that are shared by several (all) plotting backends.

physt.plotting.common.get_data(histogram, density=False, cumulative=False, flatten=False)

Get histogram data based on plotting parameters.

Parameters:
  • h (physt.histogram_base.HistogramBase) –
  • density (bool) – Whether to divide bin contents by bin size
  • cumulative (bool) – Whether to return cumulative sums instead of individual
  • flatten (bool) – Whether to flatten multidimensional bins
Returns:

Return type:

np.ndarray

physt.plotting.common.get_err_data(histogram, density=False, cumulative=False, flatten=False)

Get histogram error data based on plotting parameters.

Parameters:
  • h (physt.histogram_base.HistogramBase) –
  • density (bool) – Whether to divide bin contents by bin size
  • cumulative (bool) – Whether to return cumulative sums instead of individual
  • flatten (bool) – Whether to flatten multidimensional bins
Returns:

Return type:

np.ndarray

physt.plotting.common.get_value_format(value_format=<class 'str'>)

Create a formatting function from a generic value_format argument.

Parameters:value_format (str or Callable) –
Returns:
Return type:Callable
physt.plotting.common.pop_kwargs_with_prefix(prefix, kwargs)

Pop all items from a dictionary that have keys beginning with a prefix.

Parameters:
  • prefix (str) –
  • kwargs (dict) –
Returns:

kwargs – Items popped from the original directory, with prefix removed.

Return type:

dict

physt.plotting.matplotlib module

Module contents

Plotting for physt histograms.

Available backends

  • matplotlib
  • vega
  • plotly (simple wrapper around matplotlib for 1D histograms)
  • folium (just for the geographical histograms)

Calling the plotting functions

Common parameters

There are several backends (and user-defined may be added) and several plotting functions for each - we try to keep a consistent set of parameters to which all implementations should try to stick (with exceptions).

All histograms

write_to : str (optional)
Path to file where the output will be stored
title : str (optional)
String to be displayed as plot title (defaults to h.title)
xlabel : str (optional)
String to be displayed as x-axis label (defaults to corr. axis name)
ylabel : str (optional)
String to be displayed as y-axis label (defaults to corr. axis name)
xscale : str (optional)
If “log”, x axis will be scaled logarithmically
yscale : str (optional)
If “log”, y axis will be scaled logarithmically

xlim : tuple | “auto” | “keep”

ylim : tuple | “auto” | “keep”

invert_y : bool
If True, the y axis points downwards
ticks : {“center”, “edge”}, optional
If set, each bin will have a tick (either central or edge)
alpha : float (optional)
The alpha of the whole plot (default: 1)
cmap : str or list
Name of the palette or list of colors or something that the respective backend can interpret as colourmap.

cmap_normalize : {“log”}, optional

cmap_min :

cmap_max :

show_values : bool
If True, show values next to (or inside) the bins
value_format : str or Callable
How bin values (if to be displayed) are rendered.

zorder : int (optional)

text_color : text_alpha : text_* :

Other options that are passed to the formatting of values without the prefix

1D histograms

cumulative : bool
If True, show CDF instead of bin heights
density : bool
If True, does not show bin contents but contents divided by width
errors : bool
Whether to show error bars (if available)

2D heatmaps

show_zero : bool
Whether to show bins that have no content

grid_color : show_colorbar : bool

Whether to display a colorbar next to the plot itself
class physt.plotting.PlottingProxy(h)

Bases: object

Proxy enabling to call plotting methods on histogram objects.

It can be used both as a method or as an object containing methods. In any case, it only forwards the call to the universal plot() function.

The __dir__ method should offer all plotting methods supported by the currently selected backend.

Example

plotter = histogram.plot plotter(…) # Plots using defaults plotter.bar(…) # Plots as a specified plot type (“bar”)

Note

Inspiration taken from the way how pandas deals with this.

physt.plotting.plot(histogram, kind=None, backend=None, **kwargs)

Universal plotting function.

All keyword arguments are passed to the plotting methods.

Parameters:
  • histogram (physt.HistogramBase) –
  • kind (Optional[str]) – Type of the plot (like “scatter”, “line”, …), similar to pandas
  • backend (Optional[str]) –
physt.plotting.set_default_backend(name)

Choose a default backend.

Parameters:name (str) –