Need help with rsmf?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

156 Stars 9 Forks 127 Commits 6 Opened issues


Right-size my figures

Services available


Need anything else?

Contributors list

# 162,391
97 commits
# 572,815
6 commits

PyPI version Documentation Status rsmf Code style: black

rsmf (right-size my figures)

When I am writing a paper I am a bit picky about the figures. It is especially important for me that the fonts and font sizes match the surrounding document. As I usually plot with matplotlib I created this library to help with that. This library provides a means to automatically adjust figure sizes and font sizes in matplotlib to fit the ones in commonly used scientific journals. Currently

are supported.


You can get the latest release version from PyPI.

pip install rsmf
To get the latest development version you have to install the package from GitHub.
pip install git+

The package depends on matplotlib's PGF backend. To be able to use it, you need to have a working TeX distribution with

installed (see further Issue #2).


A detailed explanation of usage is given in the docs.


You need to tell rsmf how you set up your document by invoking

. This can be done in two ways. Either, you give rsmf the
string used for setting up the document, as in
import rsmf
formatter = rsmf.setup(r"\documentclass[a4paper,12pt,noarxiv]{quantumarticle}")
in front of the string is necessary so that
is not mistaken for an escape sequence. If you have your document stored locally, there is an even more convenient way: you can just supply rsmf with the path to your main tex file (the one containing the document setup) and it will find that out for itself:
formatter = rsmf.setup("example.tex")
This is especially cool because rsmf will automatically adjust the plots when the underlying document class is changed without any needs to change python code! This makes swapping journals a lot easier.

If the document class you're targeting is not supported by

, you can still use it. In that case you have to extract the relevant measurements yourself and use
. A detailed explanation is given in the docs.


The setup routine will return a formatter. This formatter can then be used to create matplotlib figure objects by invoking the method

. It has three arguments:
  • aspect_ratio
    (float, optional): the aspect ratio (width/height) of your plot. Defaults to the golden ratio.
  • width_ratio
    (float, optional): the width of your plot in multiples of
    . Defaults to 1.0.
  • wide
    (bool, optional): indicates if the figures spans two columns in twocolumn mode, i.e. if the figure* environment is used, has no effect in onecolumn mode . Defaults to False.

This is the place where you set the width of your plots, not in the LaTeX document. If you include the resulting figure with a different width, the font sizes will not match the surrounding document!

For example, a regular figure is created via ```python fig = formatter.figure(aspect_ratio=.5)

... some plotting ...


and included via
tex \begin{figure} \centering \includegraphics{example} \caption{...} \end{figure}
A wide figure that spans 80% of the page on the other hand is created by
python fig = formatter.figure(width_ratio=.8, wide=True)

... some plotting ...


and included via the multi-column `figure*` environment:
tex \begin{figure*} \centering \includegraphics{examplewide} \caption{...} \end{figure*} ```

Note that you should always save your figures in some sort of vectorized format, like

and that calling
before saving usually makes your plots nicer.

It is also possible to create the figure objects by hand, using

, the
routine is a convenience wrapper around this.

Other features

You can access the underlying fontsizes via

. The nomenclature follows that of LaTeX itself, so we have e.g.
. This is especially useful if you want to tweak titles, legends and annotations while still having matching fontsizes.

Using rsmf with other frameworks

You can use rsmf together with your favorite plotting framework, for example

. There is only one catch: if you use matplotlib styles or seaborn styles, you might overwrite the settings imposed by rsmf, especially regarding fontsize. To this end, the formatters have a method
that only change the underlying fontsizes. An example use would be ```python fig = formatter.figure(wide=True) sns.set(style="ticks") formatter.setdefaultfontsizes()

... some plotting ...

Sometimes these styles also overwrite other things, like the font family (serif/sans-serif). There is no correction method for that yet.


An example document alongside with a notebook for making the plots used can be found in the examples folder.

How it works

Under the hood, rsmf sets the matplotlib backend to pgf, which allows the use of LaTeX. For each supported document class, the specific column widths and font sizes are stored in code, alongside with packages that are loaded that change fonts. For quantumarticle, for example, the package lmodern is loaded into the pgf backend to get the right sans-serif font.

When calling rsmf.setup, matplotlib's rcParams are adjusted to make the fontsizes match the surrounding document. Note that formatter.figure does not mess with rcParams.


Do you have trouble setting up plots for your favorite document class and it is not supported here? Do not hesitate to make a PR!

A big thanks for contributions goes to: Samuel J. Palmer platipo

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.