zabgrab.services.plotting¶
What to plot: numeric series grouped by units, split where nothing was fetched.
This module decides the content of a plot; zabgrab.ui.plot draws it with
matplotlib. Keeping the two apart means the rules (which items can be plotted, where
lines break) are tested without matplotlib.
Functions
|
Work out a histogram of each numeric series' values. |
|
Work out what to plot. |
Classes
|
A vertical axis, shared by the series with the same units. |
|
A histogram's subplot, shared by the series with the same units. |
|
One series' counts in a histogram. |
|
A histogram to draw: counts of values in bins. |
|
One series on an axis. |
|
Everything to draw. |
|
A reference line asked for with |
|
A reference line to draw on an axis. |
|
A run of points drawn as one connected line. |
- class zabgrab.services.plotting.Segment(times, values, low=None, high=None)[source]¶
Bases:
objectA run of points drawn as one connected line.
- Parameters:
- class zabgrab.services.plotting.Line(label, segments=<factory>)[source]¶
Bases:
objectOne series on an axis.
- class zabgrab.services.plotting.RefLine(label, value, units=None)[source]¶
Bases:
objectA reference line asked for with
--hlineor--vline.- value¶
Where the line goes along its axis: a value (
--hlineon plots over time,--vlineon histograms), a count (--hlineon histograms) or POSIX seconds (--vlineon plots over time).- Type:
- classmethod parse(text)[source]¶
Read a line at a number:
[LABEL=]VALUE [UNITS].The label is everything before the last
=, so it can contain=itself. Without one, the value (and units) as given label the line.- Parameters:
text (str) – The option’s value, e.g.
Max=500,Max=500 #/m3or500.- Returns:
RefLine – The line.
- Raises:
ValueError – If there’s no value, or it isn’t a finite number.
- Return type:
Examples
>>> RefLine.parse("Max value=500") RefLine(label='Max value', value=500.0, units=None) >>> RefLine.parse("Max temp=26.5 °C") RefLine(label='Max temp', value=26.5, units='°C') >>> RefLine.parse("1e3") RefLine(label='1e3', value=1000.0, units=None)
- class zabgrab.services.plotting.Reference(label, at)[source]¶
Bases:
objectA reference line to draw on an axis.
- at¶
Where it goes: a value for lines over time, or a position along the bins for histograms (see
zabgrab.services.binning.Bins.position()).- Type:
- class zabgrab.services.plotting.Axis(units, lines=<factory>, hlines=<factory>, vlines=<factory>)[source]¶
Bases:
objectA vertical axis, shared by the series with the same units.
- class zabgrab.services.plotting.PlotSpec(axes, title='', log_y=False)[source]¶
Bases:
objectEverything to draw.
- zabgrab.services.plotting.plot_spec(series, coverage, ui, *, title='', log_y=False, hlines=(), vlines=())[source]¶
Work out what to plot.
- Parameters:
series (sequence of Series) – The data, e.g. a merged dataset’s series.
coverage (sequence of (float, float)) – The time ranges that were fetched, sorted and not overlapping (POSIX seconds). Lines break between ranges, so gaps nobody fetched aren’t drawn as if the data were continuous, while sparse data inside a fetched range is still joined up.
ui (UI) – Warns about text items that are left out.
title (str, optional) – The figure title.
log_y (bool, optional) – Use log scales for the vertical axes. Lines with values of zero or less, which can’t be shown on them, are warned about.
hlines (sequence of RefLine, optional) – Horizontal reference lines at values, drawn on every axis or those with their units.
vlines (sequence of RefLine, optional) – Vertical reference lines at times (POSIX seconds), drawn on every axis or those with their units.
- Returns:
PlotSpec – One axis per unit, each with a line per numeric series.
- Raises:
ZabgrabError – If there’s nothing numeric to plot (no series, or only text items).
- Return type:
- class zabgrab.services.plotting.Bars(label, counts)[source]¶
Bases:
objectOne series’ counts in a histogram.
- class zabgrab.services.plotting.BarAxis(units, bars=<factory>, hlines=<factory>, vlines=<factory>)[source]¶
Bases:
objectA histogram’s subplot, shared by the series with the same units.
- vlines¶
Vertical reference lines, at positions along the bins (see
zabgrab.services.binning.Bins.position()).
- class zabgrab.services.plotting.HistogramSpec(bins, axes, title='', log_y=False)[source]¶
Bases:
objectA histogram to draw: counts of values in bins.
- zabgrab.services.plotting.histogram_spec(series, bins, ui, *, title='', log_y=False, hlines=(), vlines=())[source]¶
Work out a histogram of each numeric series’ values.
- Parameters:
series (sequence of Series) – The data.
bins (Bins) – The bins (see
zabgrab.services.binning.Bins).ui (UI) – Warns about text items that are left out.
title (str, optional) – The figure title.
log_y (bool, optional) – Use log scales for the counts.
hlines (sequence of RefLine, optional) – Horizontal reference lines at counts, e.g. to see which bins exceed a limit, drawn on every axis or those with their units.
vlines (sequence of RefLine, optional) – Vertical reference lines at values, placed along the bins (see
position()), on every axis or those with their units. Lines inside an open-ended bin are warned about.
- Returns:
HistogramSpec – One subplot per unit, each with a set of bars per numeric series.
- Raises:
ZabgrabError – If there’s nothing numeric to count (no series, or only text items).
- Return type: