Visualizations Chord
Text formatting
The many text formatting options include multi-line label wrapping, size, and color.
Sample data
Let's import PlotAPI and load our sample data.
from plotapi import Chord
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"]
Demonstration
Font size
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.
Chord(matrix, names, colors="reds",
font_size_large="30").show()
Single-colored label
To change the colour of our labels, we can set a HEX colour code to the label_colors
parameter.
Chord(matrix, names,
label_colors="#B362FF",
callout_line_color="#B362FF").show()
Multi-coloured labels from a list
To change the colour of our labels, we can set a HEX colour code to the label_colors
parameter.
Chord(matrix, names,
label_colors=['red','#00ff99','blue','pink','orange','cyan']).show()
Multi-coloured labels matching chord colours
Chord(matrix, names,
label_colors_match=True, curved_labels=True).show()
Text wrapping
Label wrapping is controlled with by the wrap_labels
parameter which is True
by default.
Let's use longer entries for names
to demonstrate text wrapping.
names = [
"Exciting Action",
"Fun Adventure",
"Hilarious Comedy, a very long one",
"Drama",
"Fantasy",
"Chilling Thriller"
]
Chord(matrix, names, label_colors_match=True).show()
Custom wrapping
We can also specify the allowed label width before wrapping.
Chord(matrix, names,
wrap_labels_width=150).show()
Wrapping disabled
Let's demonstrate label wrapping set to disabled.
We've adjusted the margin to keep the labels visible.
Chord(
matrix,
names,
label_colors_match=True,
margin=50,
wrap_labels=False,
).show()