Skip to content
Polytope

Python and figures

Paper figures, notebooks, and Python demos use the same colors and type as the web pages.


In this chapter 8 pages

Install

sh
pip install "polytope-theme[matplotlib,plotly]"

The package has no required dependencies. The extras are matplotlib, plotly, gradio, streamlit, and all.

matplotlib

python
import matplotlib.pyplot as plt
import polytope_theme as ply
from polytope_theme.mpl import label_lines

ply.use("light")            # or "dark" for slides and dark pages

fig, ax = plt.subplots()
for name in ["GCN", "GAT", "SCN"]:
    ax.plot(x, results[name], label=name)
label_lines(ax)            # direct labels at the line ends, in text color
fig.savefig("figure.pdf")

The style sets the categorical color cycle, a quiet y grid, no top or right spines, and Libre Franklin when it is installed. Install the font from Google Fonts for exact type; matplotlib falls back to DejaVu Sans otherwise.

Synthetic example: a line chart with three labeled series and a bar chart, drawn with the light matplotlib style.
Figure 1.The light style on synthetic data. Lines carry direct labels; bars use the first categorical color.

Colormaps

python
ax.imshow(adjacency, cmap="ply-sequential")   # magnitude: one hue, light to dark
ax.imshow(signed, cmap="ply-diverging")       # sign: cobalt to tomato, gray at zero

plotly

python
import plotly.express as px
from polytope_theme import plotly_theme

plotly_theme.register()                     # adds "polytope" and "polytope_dark"
px.line(df, x="epoch", y="loss", color="model", template="polytope")

Gradio

python
import gradio as gr
from polytope_theme import gradio_theme

with gr.Blocks() as demo:
    ...
demo.launch(theme=gradio_theme.theme("auto"))   # gradio 4 and 5: gr.Blocks(theme=...)

Streamlit

python
from polytope_theme import streamlit_theme
streamlit_theme.write_config(".streamlit/config.toml", mode="light")
# refuses to replace a config.toml it did not write; pass overwrite=True to force

Rules that carry over

  • Series colors go in the fixed order. Past eight series, ply.categorical() raises an error: fold the rest into "Other" or split into small multiples.
  • Scatter plots and small multiples use the first three colors only. Any two points can sit side by side there, and only three colors stay distinct for every reader.
  • Status colors (good, warning, serious, critical) mean state, never "series 4", and always come with a label or marker.