3

Changing Font Sizes

 1 year ago
source link: https://datacrayon.com/posts/plotapi/sankey/changing-font-sizes/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Preamble

from plotapi import Sankey

Sankey.set_license("your username", "your license key")

Introduction

The Plotapi Sankey diagram font-sizes changed independently.

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

Dataset

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

links = [
    {"source":"Group A", "target":"Rank 1", "value": 1000},
    {"source":"Group B", "target":"Rank 1", "value": 300},
    {"source":"Group B", "target":"Rank 2", "value": 600},
    {"source":"Group B", "target":"Rank 3", "value": 400},
    {"source":"Rank 1", "target":"Club A", "value": 700},
    {"source":"Rank 1", "target":"Club B", "value": 400},
    {"source":"Rank 1", "target":"Club C", "value": 200},
    {"source":"Rank 2", "target":"Club B", "value": 200},
    {"source":"Rank 2", "target":"Club C", "value": 400},
    {"source":"Rank 3", "target":"Withdrawn", "value": 400},
    {"source":"Club A", "target":"The Most Amazing Prize", "value": 500},
]

We can add many sources and targets in any arrangement.

Visualisation

The font-sizes can be adjusted through a combination of the following:

  • title_font_size - to change the title font-size.
  • node_font_size - to change the node label font-size.
  • link_font_size - to change the link label font-size.

Let's demonstrate these in action.

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

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

Sankey(links, title="Font-size demonstration",
       node_font_size=10,
       link_font_size=30,
       title_font_size=30).show()

Plotapi - Sankey Diagram

Font-size demonstrationGroup AGroup BRank 1Rank 2Rank 3Club AClub BClub CWithdrawnThe Most AmazingPrize1000300600400700400200200400400500Produced with Plotapi

Below are the default sizes for reference.

Sankey(links, title="Font-size demonstration").show()

Plotapi - Sankey Diagram

Font-size demonstrationGroup AGroup BRank 1Rank 2Rank 3Club AClub BClub CWithdrawnThe MostAmazingPrize1000300600400700400200200400400500Produced with Plotapi

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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK