Binder Github

Themes

Themes can be used to customize the appearance of Sankey diagrams. sankee contains a few built-in themes, but you can also create your own themes for additional control. Let’s get started by setting up and initializing our packages.

[1]:
import sankee
import ee

ee.Initialize()

The Default Theme

sankee includes a default theme it will use unless you specify one. To demonstrate, we’ll look at urban expansion around Houston, Texas between 1986 and 2020.

[2]:
aoi = ee.Geometry.Point([-95.78867372638199, 29.773539101705214]).buffer(30_000)
sankee.datasets.LCMS_LU.sankify(
    years=[1986, 2020],
    region=aoi,
    n=100,
    title="Urban Expansion in Houston, TX",
)

Built-in Themes

You can override the default theme using the theme argument to sankify. Using theme="d3" will give us a similar appearance to a Sankey diagram from the d3-sankey library.

[3]:
sankee.datasets.LCMS_LU.sankify(
    years=[1986, 2020],
    region=aoi,
    n=100,
    title="Urban Expansion in Houston, TX",
    theme="d3"
)

Or we can use theme="simple" to get a slightly more minimalist theme.

[4]:
sankee.datasets.LCMS_LU.sankify(
    years=[1986, 2020],
    region=aoi,
    n=100,
    title="Urban Expansion in Houston, TX",
    theme="simple"
)

Building a Custom Theme

The theme argument accepts either the name of a built-in theme or a custom sankee.themes.Theme object. You can create your own Theme object to define a custom style. Let’s try that.

Title and Label Styles

The other way to customize a theme is by specifying CSS properties to apply to the node labels and figure title. We’ll add those to the theme parameters we defined above to finish our custom theme.

[7]:
label_style = """
    font-style: italic;
    font-size: 18px;
    color: #4e6980;
    letter-spacing: 2px;
"""

title_style = """
    font-size: 24px;
    font-weight: 900;
    font-variant: small-caps;
    color: #4e6980;
"""

custom_theme = sankee.Theme(
    link_kwargs=dict(color="rgba(0, 180, 255, 0.1)"),
    node_kwargs=dict(thickness=100, pad=100, line=dict(width=4, color="#628eb3")),
    label_style=label_style,
    title_style=title_style,
)

The final product with our custom node, link, label, and title styles:

[8]:
sankee.datasets.LCMS_LU.sankify(
    years=[1986, 2020],
    region=aoi,
    n=100,
    title="Urban Expansion in Houston, TX",
    theme=custom_theme
)