Skip to main content

Make standalone interactive HTML charts to explore time series datasets

Project description

Thumbnail screenshot of xplorts productivity explorer Explore time series datasets

xplorts ("explore-ts") is a collection of Python tools to make standalone HTML documents containing interactive charts. It is particularly aimed at showing time series data (hence the "ts") with annual, quarterly or monthly periodicity, such as that published by national statistical institutes by way of national accounts, productivity, or labour markets series.

Once created, the HTML documents can be used with any web browser. They do not need an active internet connection.

Installation

pip install xplorts

Demo

To see an interactive sample data explorer, try Explore UK output per hour worked.

Source: Office for National Statistics licensed under the Open Government Licence v.3.0

Steps to make explorer for ONS labour productivity data

  1. Download Output per hour worked, UK from the ONS web site.

  2. Open a Terminal window (Macintosh) or Command prompt window (Windows).

  3. Extract productivity, gross value added and labour data using the utility script ukons_lprod_to_csv.py. The extracted time series will go into a file outputperhourworked.csv in the folder next to the original Excel dataset.

    In the command shell or terminal window:

    python xplorts/utils/ukons_lprod_to_csv.py outputperhourworked.xlsx --quarterly --section
    

    Note: For older versions of Pandas you will have to open the Excel file, save it as .xls, and use that rather than the original .xlsx format.

  4. Run the module dblprod to create a stand-alone HTML labour productivity dashboard in the file outputperhourworked.html.

    In the command shell or terminal window:

    python -m xplorts.dblprod outputperhourworked.csv -d date -b industry -p lprod -g gva -l labour
    
  5. Use the explorer in any web browser.

Features

The labour productivity explorer demonstrates these features:

  • A grouped multi-line chart shows a set of related lines for one split level at a time, like time series for productivity, gross value added, and hours worked for a particular industry.
    Thumbnail screenshot of lines chart
  • A time series components chart shows a set of stacked bars in combination with a totals line, for one split level at a time, like cumulative growth time series for gross value added, hours worked (sign reversed), and productivity for a particular industry.
    Thumbnail screenshot of time series growth components chart
  • A snapshot growth components chart shows a set of stacked bars in combination with markers showing total growth, as a function of a categorical factor, like growth for gross value added and hours worked (sign reversed) by industry, along with growth in productivity, for a selectable time period.
    Thumbnail screenshot of snapshot growth components chart
  • Drop-down list and slider widgets provide interactive selection of a categorical split level or snapshot time period to show. Static screenshots are shown here, but check out the interactive sample data explorer at the link above.
    Screenshot of widgets to select industry Screenshot of widgets to select date
  • Hover tool displays data values at the cursor location.
  • Chart tools include box zoom, wheel zoom, pan, and save to file.
  • Time periods can be represented on a chart axis as nested categories like (year, quarter).
  • A categorical chart axis can represent time periods or levels of a split factor.

Using xplorts in Python

Import

Import the package into your code:

import xplorts

Package documentation

To show the docstring for the package:

xplorts?

To show the docstring for a particular module, like slideselect:

xplorts.slideselect?

Modules

Module Description
base Miscellaneous helper functions and classes.
ghostbokeh Define an abstract base class to a build pseudo-subclass of a Bokeh class.
lines Modify a Bokeh Figure by adding line charts to show several time series with a split factor.
scatter Modify a Bokeh Figure by adding scatter charts to show one or more categorical series with a split factor.
slideselect Defines a class combining select and slider widgets, with support for javascript linking to other objects.
snapcomp Modify a Bokeh Figure by adding a snapshot growth components chart, with a categorical vertical axis showing levels of a split factor, horizontal stacked bars showing growth components, and markers showing overall growth for each stack of bars.
stacks Modify a Bokeh Figure by adding a horizontal or vertical stacked bar chart showing several data series with a split factor.
tscomp Modify a Bokeh Figure by adding a time series growth components chart, with a categorical vertical axis showing levels of a split factor, horizontal stacked bars showing growth components, and a line showing overall growth.
dblprod Modify a Bokeh Figure by adding charts to show labour productivity levels or growth components.

Using xplorts on the command line

  • Install (once, possibly within a particular virtual environment)

  • Open a Terminal window (Macintosh) or Command prompt window (Windows)

  • Activate virtual environment, if relevant

    On Windows:

    activate my_env

    On Mac:

    conda activate my_env

  • Tell python to run an xplorts module

    python -m xplorts.dblprod ...
    

Getting help about command line options

Pass the option -h to any xplorts script to get help. For example:

python -m xplorts.dblprod -h
usage: dblprod.py [-h] [-b BY] [-d DATE] [-p LPROD] [-v GVA] [-l LABOUR]
                      [-g ARGS] [-t SAVE] [-s]
                      datafile

Create interactive visualiser for labour productivity levels with a split
factor

positional arguments:
  datafile              File (CSV) with data series and split factor

optional arguments:
  -h, --help            Show this help message and exit
  -b BY, --by BY        Factor variable for splits
  -d DATE, --date DATE  Date variable
  -p LPROD, --lprod LPROD
                        Productivity variable
  -v GVA, --gva GVA     Gross value added (GVA) variable
  -l LABOUR, --labour LABOUR
                        Labour variable (e.g. jobs or hours worked)
  -g ARGS, --args ARGS  Keyword arguments.  YAML mapping of mappings.  The
                        keys 'lines', 'growth_series' and 'growth_snapshot' 
                        can provide keyword arguments to pass to
                        `prod_ts_lines`, `prod_ts_growth` and 
                        `prod_growth_snapshot`, respectively.
  -t SAVE, --save SAVE  Interactive .html to save, if different from the
                        datafile base
  -s, --show            Show interactive .html

xplorts scripts

Script Description
dblprod Create a labour productivity dashboard, with three charts including:
  • a lines chart showing levels of labour productivity, gross value added, and labour,
  • a time series growth components chart showing cumulative growth in labour productivity, gross value added, and labour, and
  • a snapshot growth components chart showing period-on-period growth in labour productivity, gross value added, and labour.
lines Create a line chart showing several time series with a split factor. Widgets select one split factor category at a time.
scatter Create scatter chart showing one or more time series with a split factor. Widgets select one split factor category at a time.
snapcomp Create a snapshot growth components chart, with a categorical vertical axis showing levels of a split factor, horizontal stacked bars showing growth components, and a line showing overall growth. A widget selects one time period at a time.
stacks Create stacked bar chart showing several data series with a split factor. Widgets select one split factor at a time (or one time period at a time if the split factor is plotted as a chart axis).
tscomp Create a time series growth components chart, with time periods along the horizontal axis, vertical stacked bars showing growth components, and a line showing overall growth. Widgets select one split factor category at a time.
utils/ukons_lprod_to_csv.py Extract data from ONS labour productivity datasets such as Output per hour worked, UK, in a format suitable for use with xplorts charts.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xplorts-0.4.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

xplorts-0.4-py3-none-any.whl (78.9 kB view details)

Uploaded Python 3

File details

Details for the file xplorts-0.4.tar.gz.

File metadata

  • Download URL: xplorts-0.4.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.10.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

File hashes

Hashes for xplorts-0.4.tar.gz
Algorithm Hash digest
SHA256 8dceccc2db773b7d752f987a35060a08b8877a8583e42592f4980cf24cfae29d
MD5 ab557914ffba6ca36d7efe78fab6e4b5
BLAKE2b-256 d99d9f4459cbcc10a520ca71426bc9f028ec3944269df7f6be1a289c643d56d0

See more details on using hashes here.

File details

Details for the file xplorts-0.4-py3-none-any.whl.

File metadata

  • Download URL: xplorts-0.4-py3-none-any.whl
  • Upload date:
  • Size: 78.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.26.0 requests-toolbelt/0.10.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.13

File hashes

Hashes for xplorts-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 320063a2363969c281c8adcc374b68d29a888d4d8fb120d60d8d1788f674dc65
MD5 ca05009e7bb0590d676aea3d662cc9ea
BLAKE2b-256 766c86e0f4c403e0da83f36406aabd1a28a5db7803db5044e0d4ab7a48bd08ad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page