Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Python Customised Visualisations

David Plummer
Right tool for the job

Algorithms

Python R

C#
KNIME C++
Java
Julia
Data Fortran
Speed
Evolution of KNIME visualisations

Extract
Transform Process Visualise
Load
Plotly
• Wide selection of charts
• Interactivity
• Customisable
• Chart types
• Themes
• Cross programming language
support
• Plotly Express
Example Customisation
Plotly concepts

Create Render

plotly express

Plotly graph object


io
subplots
traces
plotly.js
layout Data
D3.js stack.gl
figure Layout
JSON File
Runs in KNIME Runs in browser
Basics of a Python view
Python dependencies

Conda:
conda install –c conda-forge plotly python-kaleido

Static image export from Plotly:


https://github.com/plotly/Kaleido

Note: Developer was a Plotly employee. They no longer work for Plotly, and the
package is not under active maintenance.
Python code - imports
Python code – plot chart

pandas data frame


name of column with y data
name of column with x data
name of column with categories

dictionary
key: pandas column name
value: display name

Add titles and options for chart

Pass figure to Knime to display


Python code – export image

Default settings
• Could be passed as variables

Plotly object

Add port to Python view

Add output image port Click here


Click here
Themed Python view
Banner title Grid styling

Custom font

Background colour
Custom colours
Visualisation layout

Visualisation size (pixels)


Creating a custom template
Import Plotly io library

Create a new template based


upon the ‘Plotly’ style

Define some standard items

Update items in template


Use dict() instead of {} to reduce
number of quoted items.

Note:
title_font_size is shorthand in
plotly for nested dictionaries:

“title”: {
“font”: {
“size” : 24
}
}
Custom colour scheme

Colours are allocated to


traces sequentially from
this list
Set up axes and grid

Show vertical gridlines

Show ticks and axis line

Show zero line and format

Dotted horizontal
gridline

Reduce the paper size 5%


down from top of title
Background colour for title

Name of the shape


Bounding box in PAPER co-
ordinates not visualisation size
1.3
1.01 2.0
-0.2

Make the template default for the chart


Creating a theme template node
Python
Theme Component Visualisation Component

Pickled Output:
Mechanism for serialising data
and sending it down the wire
Share code between nodes
Theme Component
Visualisation Component
Create a multi-line string containing the code

Input string to Input(pickled) port

Execute the string.

Note:
Security implications of executing arbitrary code!!
Do you trust the code you are executing.

Output string to Output(pickled) port


Further information
• Knime
• https://docs.knime.com/latest/python_installation_guide/
• https://knime-python.readthedocs.io/en/stable/
• Plotly
• https://plotly.com/python/
• https://plotly.com/python-api-reference/

You might also like