Post

Want to make publication-ready figures come straight from Python without having to do any manual editing? Are you fed up with axes labels being unreadable during your presentations? Follow this short tutorial including code examples! 👇🧵

Journals have criteria figures have to adhere to. Generally, a full-width figure should be 7 inch wide and font sizes cannot be smaller than 7 pts. If you get into the habit of always creating figures that fit these criteria this will save you a lot of time when submitting.

The font size of each plot element can be easily set with seaborn. Write a function like this that sets the font size and any other style element you like to have in all your plots and the function each time before plotting (link to the code in the last post).

0 reposts4 likes

I used to put plt.style.use("neuro.mplstyle") at the top of every script. Now I just make a lib/__init__.py that handles imports and sets the style, so when I make a quick script to test an idea I can `from lib import np, plt` and have everything I need.

Full width figures typically have four panels next to each other, a good rule of thumb is that a single panel is 1.75 by 1.75 inch. Create two figure panels like this: f, axs = plt.subplots(1, 2, figsize=(1.75 * 2, 1.75), dpi=300) ⚠️ If it's too small increase the dpi, not the figsize!

A note about colors 🌈 Imagine you made eight figures and your PI asks you to change the color of an element you've consistently plotted green into orange. If you define your colors in the plotting function you only have to change it there and rerun the plotting scripts, this save a lot of time!

The workflow: Python plots single panels, saved as pdfs. Create an empty figure of 7 inch (180 mm) wide in Illustrator and place the panels as links. Add the panel letters (a,b,c). Now, if a new version of a panel is generated you just have to click update links in Illustrator and it's there. 🤩

Good tips! The only thing I dislike about this workflow is that the ai file with links is no longer self-contained, so harder to share with collaborators. I usually go straight for multi-panel in python (using Gridspec), and only use illustrator for adding the panel letters

I recently tried going one step further with an LLM assist: save plots as PDF + JSON sidecar with the position of the axes within the PDF, then an assembly script merges the panels and adds labels nicely aligned based on the sidecar data. Works, but not well enough to keep me doing it.