vislib¶
Introduction¶
vislib is a library that wraps common javascript visualization libraries. The variety and capabilities of javascript visualization libraries far exceed what exists in python. Though native python libraries will always have better integration support, the goal here is to provide a quick and dirty way to embed rich html visualizations as iframes into an iptyhon environment or generate them as standalone html files.
The core vislib package provides an abstraction that makes it easy to add new wrappers for additional javascript libraries. It uses the jinja2 templating library and some standard boilerplate templates to just expose the raw capabilities of each library.
Each visualization is an attempt to strike a balance between completeness, consistency, and simplicity for the visualization API. Feedback is welcome!
Currently Supported Visualizations¶
vis.js¶
A library for rich interactive timelines: visjs timelines
-
vislib.visjs.
timeline
(data, content_field='contents', start_field='start', end_field=None, type_field=None, group_field=None, title=None, width=600, height=400, **options)¶ Renders a vis.js timeline component (See http://visjs.org/docs/timeline/ for more information)
Example: >>> from vislib.visjs import timeline >>> timeline([{'text': 'first item', 'start': '2018-05-21 17:30:08.202'}, >>> {'text': 'second item', 'start': "2018-05-21 17:31:53.712"}, >>> {'text': 'third item', 'start': "2018-05-21 18:14:05.843"}], content_field='text', title='example1')
Parameters: - data – a pandas DataFrame or list of dictionaries that specify the data to visualize
- content_field – the field representing the textual contents of each timeline node
- start_field – the field representing the start time (as a date or string) of each timeline node
- end_field – the field representing the end time of each timeline node
- type_field – the field representing the type of node. Can be ‘box’, ‘point’ (default), ‘range’, or ‘background’
- group_field – the field representing the group name to assign the timeline node to. Groups appear as swimlanes in the timeline view if they exist
- title – A title to assign to your timeline view, this will be the filename of the saved html file on disk
- height –
- width –
- options – Additional options to specify for the timeline. See http://visjs.org/docs/timeline/#Configuration_Options
Returns: in ipython, a visualized timeline, otherwise None, but triggers opening your default browser with the generated file
Taucharts¶
A d3 based charting library that elegantly mixes power and simplicity, allowing for unique faceted charts: taucharts
-
vislib.taucharts.
chart
(data, x, y, color=None, title=None, width=800, height=400, **options)¶ Renders a basic taucharts chart with the given data. See https://www.taucharts.com/
>>> from vislib.taucharts import chart >>> chart([{'item': 'car', 'amount': 1}, >>> {'item': 'book', 'amount': 10}, >>> {'item': 'bed', 'amount': 3}], x='item', y='amount', title='Taucharts example')
Parameters: - data – a pandas DataFrame or list of dictionaries that specify the data to visualize
- x – the field to map as the x coordinate
- y – the field to map as the y coordinate
- color – the field to map to the color of the datapoints
- title – A title to assign to your timeline view, this will be the filename of the saved html file on disk
- width –
- height –
- options – Additional options to pass as the chart definition (See https://api.taucharts.com/basic/index.html) Some common options include * type: scatterplot, line, bar, horizontalBar, stacked-bar, stacked-area * size: field to map to the size of a node * dimensions: allows setting custom axis labels and types * guide: allows customizing visual elements of the chart presentation
Returns: in ipython, a visualized chart, otherwise None, but triggers opening your default browser with the generated file
Treant¶
A tree generation library that generates customizable interactive tree hierarchies: Treant
-
vislib.treant.
tree
(data, title=None, width=800, height=400, styling='', **options)¶ Renders a Treant.js tree. See http://fperucic.github.io/treant-js/
Example: >>> from vislib.treant import tree >>> tree({ >>> 'text': { 'name': "Parent node" }, >>> 'children': [{ >>> 'text': { 'name': "First child" } >>> },{ >>> 'text': { 'name': "Second child" } >>> }] >>> })
Parameters: - data – A dict in the json format specified for treant.
- title – A title to assign to your timeline view, this will be the filename of the saved html file on disk
- width –
- height –
- styling – Custom raw css to apply to the chart
- options – Additional chart options for the treant tree
Returns: in ipython, a visualized tree, otherwise None, but triggers opening your default browser with the generated file