Ersilia Book
  • 🤗Welcome to Ersilia!
    • The Ersilia Open Source Initiative
    • Ten principles
    • Ersilia's ecosystem
  • 🚀Ersilia Model Hub
    • Getting started
    • Online inference
    • Local inference
    • Model contribution
      • Model template
      • Model incorporation workflow
      • Troubleshooting models
      • BioModels annotation
    • For developers
      • Command line interface
      • CI/CD workflows
      • Test command
      • Testing playground
      • Model packaging
      • Inputs
      • Codebase quality and consistency
      • Results caching
  • 💊Chemistry tools
    • Automated activity prediction models
      • Light-weight AutoML with LazyQSAR
      • Accurate AutoML with ZairaChem
      • Model distillation with Olinda
    • Sampling the chemical space
    • Encryption of AI/ML models
  • AMR chemical collections
  • 🙌Contributors
    • Communication channels
    • Tech stack
    • Internships
      • Outreachy Summer 2025
      • Outreachy Winter 2024
      • Outreachy Summer 2024
      • Outreachy Winter 2023
      • Outreachy Summer 2023
      • Outreachy Winter 2022
      • Outreachy Summer 2022
  • 📑Training materials
    • AI2050 intro workshop
    • AI2050 AI for Drug Discovery
    • Introduction to ML for Drug Discovery
    • Python 101
    • External resources
  • 🎨Styles
    • Brand guidelines
    • Slide and document templates
    • Scientific figures with Stylia
    • Coding style
  • 🌍About Us
    • Where to find us?
    • Diversity and inclusion statement
    • Code of conduct
    • Open standards and best practices
    • Ersilia privacy notice
    • Strategic Plan 2025-2027
    • Ersilia, the Invisible City
Powered by GitBook

2025, Ersilia Open Source Initiative

On this page
  • Getting started
  • Installation
  • Create a single panel figure
  • Create a multipanel figure
  • Sizes
  • Figure size
  • Font size
  • Marker sizes
  • Line widths
  • Colors
  • Named colors
  • Color maps

Was this helpful?

  1. Styles

Scientific figures with Stylia

Sytlia is a small Python library for styling plots

PreviousSlide and document templatesNextCoding style

Last updated 6 months ago

Was this helpful?

is a small package to stylize plots in Python so that they are publication-ready. Stylia provides modified axes (ax) that can be used as drop-in replacements for Matplotlib axes.

Getting started

Installation

First make sure that you have the Arial font installed in your computer (Linux systems do not have it preinstalled). The best is to install Arial in the conda environment you are using:

conda install -c conda-forge mscorefonts

You can read more about fonts and Matplotlib in this excellent from the Alexander Lab.

Stylia is constantly evolving, so we recommend that you install it directly from the .

git clone https://github.com/ersilia-os/stylia.git
cd stylia
pip install -e . 

Create a single panel figure

import stylia as st
import numpy as np

fig, axs = st.create_figure(1,1)
ax = axs[0]

x = np.random.normal(size=100)
y = np.random.normal(size=100)

ax.scatter(x, y)

st.save_figure("my_single_plot.png")

Create a multipanel figure

import stylia as st
import numpy as np

# create a figure to be used in a slide
fig, axs = st.create_figure(nrows=2, ncols=2, width_ratios=[2, 1])

# get data
x = np.random.normal(size=100)
y = np.random.normal(size=100)

# first plot, access with flat subplots coordinates (0)
ax = axs[0]
# a default color is used
ax.scatter(x, y)
# write labels to axis, title and numbering of the subplot
st.label(
    ax,
    title="My first plot",
    xlabel="This is the X axis",
    ylabel="This is the Y axis",
    abc="A",
)

# second plot, acces with subplots 2D coordinates (0,1)
ax = axs[0, 1]
# use a named color
named_colors = st.NamedColors()

def my_scatterplot(ax, x, y):
    ax.scatter(x, y, color=named_colors.get("red"))

my_scatterplot(ax, x, y)
# write only a new title (the rest are defaults)
st.label(ax, title="My second plot")

# third plot, access with next() method
ax = axs.next()
cmap = st.ContinuousColorMap()
cmap.fit(x)
colors = cmap.get(x)
ax.scatter(x, y, color=colors)

# fourth plot
ax = axs[1, 1]
# add transparency
ax.scatter(x, y, color=named_colors.get("blue", alpha=0.2))

# save figure
st.save_figure("my_grid_plot.png")

Sizes

Figure size

  • SINGLE_COLUMN_WIDTH: 90 mm or 3.54 in

  • TWO_COLOUMNS_WIDTH: 180 mm or 7.09 in

These variables are built-in within Stylia. You can access them as follows:

from stylia import TWO_COLUMNS_WIDTH

Font size

  • FONTSIZE_SMALL: 5

  • FONTSIZE: 6

  • FONTSIZE_BIG : 8

Marker sizes

  • MARKERSIZE_SMALL: 5

  • MARKERSIZE: 10

  • MARKERSIZE_BIG: 30

Line widths

  • LINEWIDTH: 0.5

  • LINEWIDTH_THICK: 1.0

Colors

Named colors

You can use predefined colors:

from stylia import NamedColors

named_colors = NamedColors()
color = named_colors.get('blue')

Available color names are:

  • 'red'

  • 'blue'

  • 'green'

  • 'orange'

  • 'purple'

  • 'yellow'

  • 'gray'

  • 'white'

  • 'black'

Color maps

Continuous color maps

Color maps can be created with the fit method.

from stylia import ContinuousColorMap
import numpy as np

cmap = ContinuousColorMap("spectral")
x = np.random.normal(size=100)
y = np.random.normal(size=200) / 2
cmap.fit(x)
# get colors of x
colors_x = cmap.get(x)
# get colors of y based on the x scale
colors_y = cmap.get(y)

Available color maps are:

  • 'spectral'

  • 'viridis'

  • 'coolwarm'

Discrete colormaps

Discrete colormaps are work in progress

We follow the . Please read those style guidelines carefully. In brief, the entire figure should be have the following sizes:

Please note that, by default, we use . Non-scientific color maps look brighter, though. If you want to use non-scientific color maps, simply specify ContinuousColorMap("spectral", scientific=False).

🎨
Stylia
Matplotlib
blogpost
GitHub repository
Nature Figure Guidelines
Scientific Color Maps