Skip to main content

Easy publication-ready matplotlib plots for ML papers and posters.

Project description

Agustinus' Very Opiniated Publication-Ready Plotting Library

PyPI version codecov pytest mypy-lint ruff-lint ruff-format


I love TikZ (btw). I love tikzplotlib. I've been an advocate for the latter (proof). However, tikzplotlib is as good as dead. I need to move on.

[!IMPORTANT] Here's what I use now for all my publication needs. This library is designed to be very opiniated. Beauty is in the eye of the beholder. Also, it is very simple, just a single file and that's it.

[!NOTE] Of course I still use TikZ whenever possible (e.g. Fig. 1 in a paper, diagrams, etc.)

Examples

Left: ICML (letter size), single-column layout. Right: A0 landscape poster, 3-column layout.

       

import pub_ready_plots as prp

...

prp.get_context(
-   layout=prp.Layout.ICML,
+   layout=prp.Layout.POSTER_LANDSCAPE,
    ...
)

...

Installation

Still with me? Still want to use this library? Here's how:

pip install pub-ready-plots

Quick usage

import pub_ready_plots as prp

# Wrap you current plotting script with this `with` statement.
# By default, this will create a full-width, 0.15*\textheight plot that conforms
# to the ICLR template.
with prp.get_context(layout=prp.Layout.ICLR) as (fig, axs):
    # Do whatever you want with `fig` and `axs`
    ...

    # Once your done, save it, but do NOT set `tight_layout=True`!
    fig.savefig("filename.pdf")

Then in your LaTeX file, include the plot as follows:

\includegraphics[width=\linewidth]{filename.pdf}

[!IMPORTANT] The argument width=\linewidth is crucial! Also, do not specify the height option! Otherwise, your plot is distorted. (All measurements have been done in pub-ready-plots.)

That's it! But you should use TikZ more. Anyway, see the full, runnable example in examples/simple_plot.py See here for available options for get_context()!

[!TIP] I recommend using this library in conjunction with pypalettes to avoid the generic blue-orange Matplotlib colors. Distinguish your plots from others!

Advanced usages

All available options

import pub_ready_plots as prp

with prp.get_context(
    layout=prp.Layout.ICML,  # check `Layout` for all available layouts
    width_frac=1,  # multiplier for `\linewidth`
    height_frac=0.15,  # multiplier for `\textheight`
    single_col=False,  # only works for the "icml", "aistats", "uai" layouts
    nrows=1,  # depending on your subplots, default = 1
    ncols=2,  # depending on your subplots, default = 1
    override_rc_params={"lines.linewidth": 4.123},  # Overriding rcParams
    sharey=True,  # Additional keyword args for `plt.subplots`
) as (fig, axs):
    ...

    fig.savefig("filename.pdf")

Creating plots for \wrapfigure

Say we want to have an inline figure of size 0.4\textwidth and height 0.15\textheight in our NeurIPS paper. Then all we have to do is the following:

import pub_ready_plots as prp

with prp.get_context(
    layout=prp.Layout.NEURIPS, width_frac=0.4, height_frac=0.15,
) as (fig, axs):
    # Your plot here!
    ...
    fig.savefig("mywrapfigure.pdf")

In our LaTeX doc, we can then use the wrapfig package and do the following:

Some paragraph.

\begin{wrapfigure}[11]{r}{0.4\textwidth}
  \centering
  \includegraphics[width=\linewidth]{mywrapfigure.pdf}
  ...
\end{wrapfigure}

Some other paragraph.

[!IMPORTANT] In the \begin{wrapfigure} statement, specify the correct figure size (in our case, 0.4\textwidth). Then, in the \includegraphics statement, always specify width=\linewidth without specifying the height.

Using your own styles

Two options:

  1. Use this library and update the resulting rc_params dict with your styles.
  2. Fork this repo and modify things as you wish.

Other libraries

Check out tueplots if you want a more complex library. My library is designed to achieve what I want in my papers and posters, with as little code as possible. Because of this, it is very forkable and hackable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pub_ready_plots-1.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

pub_ready_plots-1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pub_ready_plots-1.1.tar.gz.

File metadata

  • Download URL: pub_ready_plots-1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.18.0 CPython/3.9.19 Darwin/23.6.0

File hashes

Hashes for pub_ready_plots-1.1.tar.gz
Algorithm Hash digest
SHA256 9cc8293d258662ddc9754ee9346c986c84816ec87946b9a3ab771022fdce2c2d
MD5 bb7ea3ba7d73240c311d26626ad0fa61
BLAKE2b-256 3496dc663792c3ede3d7e971584e54f0511d8d462ca076b6cba6f28af5b3c0af

See more details on using hashes here.

File details

Details for the file pub_ready_plots-1.1-py3-none-any.whl.

File metadata

  • Download URL: pub_ready_plots-1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.18.0 CPython/3.9.19 Darwin/23.6.0

File hashes

Hashes for pub_ready_plots-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 465dc2cbd05ef9c0a02655603f284b1ba7ca4132667486c4d548df123db74d66
MD5 c3f3dd538059d3573df38c58d316eca2
BLAKE2b-256 39b6f166cdc354f95ccf4b3a12ba28a4245161cfef84cefe907f952aec180274

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page