# Changing the Colours

## Preamble¶

In [1]:
from plotapi import Terminus



## Introduction¶

Let's take a look at the colors parameter. This will allow us to select from a predefined set of colours, or even pass in our own!

As we can see, we have set our license details in the preamble with Terminus.set_license().

## Dataset¶

Terminus expects a list of dictionary items, these will define the flow of pixels between a source and a target.

In [2]:
links = [
{"source":"Germany", "target":"England", "value": 1000},
{"source":"France",  "target":"England", "value": 3000},
{"source":"Spain",   "target":"England", "value": 5000},
{"source":"Italy",   "target":"England", "value": 4000},
{"source":"Japan",   "target":"England", "value": 800},

{"source":"Germany", "target":"Ireland", "value": 800},
{"source":"France",  "target":"Ireland", "value": 4000},
{"source":"Spain",   "target":"Ireland", "value": 5000},
{"source":"Italy",   "target":"Ireland", "value": 3000},
{"source":"Japan",   "target":"Ireland", "value": 1000},
]


We can add many source's and target's! As they increase, we may need to adjust Terminus layout properties to accomodate the diagram's size and throughput.

## Visualisation¶

To specify colours, we can set the colors parameter to one of the following:

• A list of colour strings, e.g. ["#264653","#2a9d8f","#e9c46a","#f4a261","#e76f51"]
• The string name of a predefined set of colours from the following list: ['monsters', 'category10', 'accent', 'dark2', 'paired', 'pastel1', 'pastel2', 'set1', 'set2', 'set3', 'tableau10', 'rainbow', 'sinebow', 'yellow_red', 'yellow_brown', 'yellow_green', 'yellow_blue', 'red_purple', 'purple_red', 'purple_blue', 'orange_red', 'green_blue', 'blue_purple', 'blue_green', 'cubehelix', 'cool', 'warm', 'cividis', 'plasma', 'magma', 'inferno', 'viridis', 'turbo', 'brown_green', 'purple_green', 'pink_green', 'red_blue', 'red_grey', 'red_yellow_blue', 'red_yellow_green', 'spectral', 'blues', 'greens', 'greys', 'oranges', 'purples', 'reds'].

The default colour scheme is "rainbow".

Here we're using .show() and show_png() which outputs to a Jupyter Notebook cell, however, we may want to output to a file with .to_html() or .to_png() instead. More on the different output methods later!

In [9]:
Terminus(links).show()

Plotapi - Terminus Diagram

### Target Bar Colours¶

You can also apply colours to the target bars!

In [10]:
Terminus(links, colored_target_bars=True).show()

Plotapi - Terminus Diagram

Let's demonstrate a few colour schemes.

In [4]:
Terminus(links, colors="viridis").show_png()

In [5]:
Terminus(links, colors="spectral").show_png()

In [6]:
Terminus(links, colors=["#264653","#2a9d8f","#e9c46a","#f4a261","#e76f51"]).show_png()

In [7]:
Terminus(links, colors="turbo").show_png()


You can do so much more than what's presented in this example, and this is covered in other sections. If you want to see the full list of growing features, check out the Plotapi API Documentation. or the Plotapi Gallery.

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

Depending on the visualisation, disabling, expanding or restricting the width of the popup may be necessary.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

We can modify the popup width with the popup_width parameter.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, colors="set3", popup_width=100).show()

Plotapi - Chord Diagram

## Disabling the Popup¶

In [6]:
Chord(matrix, names, popup_enabled=False).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

# Multi-line Label Wrapping

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

Plotapi Chord labels wrap by default - this can be disabled if required.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Exciting Action", "Fun Adventure", "Hilarious Comedy", "Drama", "Fantasy", "Chilling Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Exciting Action Fun Adventure Hilarious Comedy Drama Fantasy Chilling Thriller
Exciting Action 0 5 6 4 7 4
Fun Adventure 5 0 5 4 6 5
Hilarious Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Chilling Thriller 4 5 5 5 4 0

## Visualisation¶

Label wrapping is controlled with by the wrap_labels parameter which is True by default.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [6]:
Chord(matrix, names, colors="viridis").show()

Plotapi - Chord Diagram

Let's demonstrate label wrapping set to disabled.

In [7]:
Chord(matrix, names, colors="viridis", wrap_labels=False).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

# Enabling Curved Labels

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

In some cases, curved labels may improve the look of our visualisation. They are not enabled by default because they are not suitable for all datasets - especially those which result in many small segments.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

To enable curved labels, we set curved_labels=True

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, curved_labels=True).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

# Changing the Label Colour

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

We can change the colour of the labels to something more suitable for our visualisation if needed.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

This could be a single colour, a list of colours, or even having them match the chord colours.

### Single-coloured label¶

To change the colour of our labels, we can set a HEX colour code to the label_colors parameter.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, label_colors="#B362FF").show()

Plotapi - Chord Diagram

## Multi-coloured labels from a list¶

In [5]:
Chord(matrix, names, label_colors=['red','#00ff99','blue','pink','yellow','cyan']).show()

Plotapi - Chord Diagram

### Multi-coloured labels matching chord colours¶

In [9]:
Chord(matrix, names, label_colors_match=True, curved_labels=True).show()

Plotapi - Chord Diagram
In [7]:
Chord(matrix, names, colors='cool',
label_colors_match=True, curved_labels=True).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

We can adjust the inner and outer radius scale of our Chord diagram if it suites our desired design. This will change the thickness of the segmets.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

We can control the radius scales by setting the inner_radius_scale and outer_radius_scale parameters.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, inner_radius_scale=0.3, outer_radius_scale=1.5).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

Let's take a look at some parameters that control the layout of our diagram.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

We can modify the width, margin, and rotation of our diagram.

The width parameter will also set the height, as the Plotapi Chord maintains a $1:1$ ratio.

The margin parameter expects a single float to imply an equal margin of that size.

The rotate paramater will rotate the Chord diagram around its center.

By default a Chord diagram is centered, but this can be disabled with center=False.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, width=500, margin=100, rotate=-30).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

We can adjust the font-size used for our labels.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

The font size is controlled by two parameters. These set the font-size for two views, font-size-large (@media min-width: 600px), otherwise font-size. Setting a large font-size may require adjustment of the margin parameter to avoid text-clipping.

Here we're using .show() which outputs to a Jupyter Notebook cell, however, we may want to output to a HTML file with .to_html() instead. More on the different output methods later!

Be sure to interact with the visualisation to see what the default settings can do!

In [6]:
Chord(matrix, names, colors="reds", font_size="20px", font_size_large="30px").show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

Adjusting padding may not sound exciting, but in this case, it can have some interesting effects.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

The padding parameter adjusts the padding between the Chord diagram segments. This value must be a float between or equal to $0.0$ and $1.0$. Values below $0.5$ look better.

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, padding=0.5).show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.

# Setting the Title

## Preamble¶

In [1]:
from plotapi import Chord



## Introduction¶

Plotapi Chord allows setting a title for the diagram by passing in a string.

As we can see, we have set our license details in the preamble with Chord.set_license()

## Dataset¶

Chord expects a list of names (list[str]) and a co-occurence matrix (list[list[float]]) as input.

In [2]:
matrix = [
[0, 5, 6, 4, 7, 4],
[5, 0, 5, 4, 6, 5],
[6, 5, 0, 4, 5, 5],
[4, 4, 4, 0, 5, 5],
[7, 6, 5, 5, 0, 4],
[4, 5, 5, 5, 4, 0],
]

names = ["Action", "Adventure", "Comedy", "Drama", "Fantasy", "Thriller"]


It may look more clear if we present this as a table with the columns and indices labelled. This is entirely optional.

In [3]:
import pandas as pd
pd.DataFrame(matrix, columns=names, index=names)

Out[3]:
Action Adventure Comedy Drama Fantasy Thriller
Action 0 5 6 4 7 4
Adventure 5 0 5 4 6 5
Comedy 6 5 0 4 5 5
Drama 4 4 4 0 5 5
Fantasy 7 6 5 5 0 4
Thriller 4 5 5 5 4 0

## Visualisation¶

To include a diagram title, we can pass the desired string into the title parameter.

Be sure to interact with the visualisation to see what the default settings can do!

In [4]:
Chord(matrix, names, title="Movie Genre Co-occurrence").show()

Plotapi - Chord Diagram

You can do so much more than what's presented in this example, and we'll cover this in later sections. If you want to see the full list of growing features, check out the Plotapi Documentation. and the Plotapi Gallery.