Things I Frequently Do in Matplotlib but Always Forget
Prerequisites
Making Plots Editable in Adobe
1. Use TrueType Font Type
The default is 3, which is Output Type. See this page for details.
2. Use the pgf Backend
This uses a LATEX processing system.
Using Custom Fonts
On WSL, Windows fonts are available at /mnt/c/Windows/Fonts, and you often want to use them.
Listing Available Fonts
Controlling Margins
Useful when you have long labels and need to control margins.
Colorbar-Only Plot
Use mpl.colorbar.Colorbar. ColorbarBase has been deprecated recently.
Since mpl.colors.Normalize and the return value of plt.get_cmap are callable, you can obtain the normalized value and the corresponding color as follows:
Drawing Shapes
Use patch.
Adjusting Tick Labels and Positions
Extracting a Size Legend Independently
Normally this is fine as-is, but when you adjust the size of points in a scatter plot, for example, you need to adjust the labels. In such cases, it's useful to extract the legend and redraw it.
Adjusting Subplot Spacing Nicely
Use tight_layout.