pyvoa.visualizer
Dispatch of chart requests to the visualisation backends.
AllVisu holds the drawing settings that do not depend on the backend – the
colour cycle, the logos, how many locations a chart shows and how long a name
may be – then routes each request to matplotlib, bokeh or seaborn according to
vis, and to the routine matching typeofplot, typeofhist or
typeofmap. The backends do not all offer the same charts.
Project : pyvoa Authors : Tristan Beau, Julien Browaeys, Olivier Dadoun Copyright ©pyvoa_org License : see the joint LICENSE file https://pyvoa.org/
- class pyvoa.visualizer.AllVisu(db_name=None, kindgeo=None)[source]
Bases:
objectDispatcher routing a chart request to the backend that draws it.
Every visualisation is implemented here or in one of the backend modules it delegates to.
- __init__(db_name=None, kindgeo=None)[source]
Prepare the dispatcher for one database.
Reads the geographic metadata of db_name – its ISO3 code and its granularity – unless the data is user supplied (‘in-house data’), collects the chart methods the class exposes, and settles the drawing defaults: the colour cycle, how many locations a chart shows at most when
maxcountrydisplayedis not given (12; seemaxcountry()), and the paths to the two logo files stamped on the figures. How long a location name may be before it is cut is not settled here: each chart readsmaxlettersdisplayedfrom its keyword arguments.- Parameters:
db_name (
str) – the database the charts will describe.kindgeo (
gpd.GeoDataFrame) – the geometry to draw the locations with.
- maxcountry(kwargs)[source]
Return how many locations a chart may show, as asked for.
- Parameters:
kwargs (
dict) – The drawing arguments; ‘maxcountrydisplayed’ is read from them, and the default of 12 used when it is missing.- Returns:
The cap.
- Return type:
- Raises:
PyvoaError – If the value is not a positive integer.
- decoplot()[source]
Decorate preparing the data of a time-series plot.
Keeps the first
maxcountrydisplayedlocations, cuts their names tomaxlettersdisplayedfor the labels, legends and tooltips, and sets the title, the logo and the legend of a ‘sumall’ plot.
- decohistomap()[source]
Decorate preparing the data of a histogram, a pie chart or a map.
Cuts the location names to
maxlettersdisplayedfor the labels, legends and tooltips, keeps the last date (unless a date slider is asked for), ranks the locations, caps a histogram by location atmaxcountrydisplayedof them, and gathers the rest into a ‘SumOthers’ slice for a histogram by value or a pie chart.
- decohistopie()[source]
Decorate preparing the data of a histogram or a pie chart.
Sorts the locations by decreasing value so the chart is drawn in rank order, and resolves ‘what’ to the single column the chart needs when a daily or weekly series was asked for.
- plot(**kwargs)[source]
Draw a time series with whichever backend is selected.
Dispatches to matplotlib, bokeh or seaborn according to ‘vis’, and within each to the routine matching ‘typeofplot’. The backends do not all offer the same plots: ‘compare’ and ‘spiral’ exist only in bokeh.
- Parameters:
**kwargs – the drawing arguments prepared by front, including ‘input’, ‘which’, ‘what’, ‘vis’ and ‘typeofplot’.
- Return type:
The figure built by the backend.- Raises:
PyvoaError – if the selection holds a single date, if ‘yearly’ or ‘spiral’ is asked for with more than one location or variable, or if ‘versus’ is not given exactly two variables.
- hist(**kwargs)[source]
Draw a histogram or a pie chart with whichever backend is selected.
Dispatches to matplotlib, bokeh or seaborn according to ‘vis’, and within each to the routine matching ‘typeofhist’: ‘location’ (one bar per location), ‘value’ (the locations binned by value) or ‘pie’.
- Parameters:
**kwargs – the drawing arguments prepared by front, including ‘input’, ‘which’, ‘vis’ and ‘typeofhist’.
- Return type:
The figure built by the backend.- Raises:
PyvoaError – If matplotlib is asked for a ‘typeofhist’ it does not draw.
- map(**kwargs)[source]
Draw a map with whichever backend is selected.
Dispatches to matplotlib, bokeh, seaborn or folium according to ‘vis’. A single variable is drawn: a list given as ‘which’ is reduced to its first element.
- Parameters:
**kwargs – the drawing arguments prepared by front, including ‘input’ with its ‘geometry’ column, ‘which’, ‘vis’, ‘typeofmap’ and ‘tile’.
- Return type:
The map built by the backend.- Raises:
PyvoaError – If ‘dateslider’ is asked for outside bokeh, if ‘input’ has no geometry, or if ‘vis’ names no backend that draws maps.