Skip to content

Python tips

Tessa Rhinehart edited this page Apr 18, 2025 · 2 revisions

Sam's configuration parameters put in the cell at the top of figure-making notebooks. This may be useful when creating figures for manuscripts, or just for Python Notebooks in general.

from matplotlib import pyplot as plt

small_txt = 7
med_txt = 8
big_txt = 8

# set text sizes
plt.rcParams['font.size'] = small_txt
plt.rcParams['axes.labelsize'] = med_txt
plt.rcParams['axes.titlesize'] = big_txt
plt.rcParams['xtick.labelsize'] = small_txt
plt.rcParams['ytick.labelsize'] = small_txt
plt.rcParams['legend.fontsize'] = med_txt
plt.rcParams['figure.titlesize'] = big_txt

# opaque legend (<1 is not fully opaque)
plt.rcParams["legend.framealpha"] = 1.0

# set figure size
plt.rcParams['figure.figsize']=[6,2.5]
plt.rcParams['figure.dpi'] = 300

# set default font
# plt.rcParams['font.sans-serif'] = "Gill Sans"
# plt.rcParams['font.family'] = "sans-serif"
plt.rcParams['font.sans-serif'] = "Gill Sans"

# tell matplotlib to create fonts that Illustrator understands
plt.rcParams['pdf.fonttype'] = 42
plt.rcParams['ps.fonttype'] = 42

#color and line style cycles
from cycler import cycler
default_cycler = (cycler(color=['#35aad8','#f3b61f','#8a96d7','#45b69c','#ba3b54']) +
                  cycler(linestyle=['-', '--', '-.', ':','-']))
#https://coolors.co/35aad8-f3b61f-ba3b54-45b69c-8a96d7

plt.rc('lines', linewidth=2)
plt.rc('axes', prop_cycle=default_cycler)

#use high-res 
%config InlineBackend.figure_format='retina'

Clone this wiki locally