matplotlib figure layout
Tips
早く知っておきたかったmatplotlibの基礎知識、あるいは見た目の調整が捗るArtistの話 - Qiita
matplotlib: 論文用に図の体裁を整える - Qiita
「データ視覚化のデザイン `#1」をmatplotlibで実装する - Qiita
plt.close() だけではメモリが解放されない場合がある - Qiita
hr.icon
Figure
matplotlib.pyplot.figure — Matplotlib documentation
hr.icon
Zorder
図の重ね合わせの順番を変える
pylab_examples example code: zorder_demo.py
http://matplotlib.org/examples/pylab_examples/zorder_demo.html
hr.icon
Room
Move the edge of an axes to make room for tick labels
https://matplotlib.org/faq/howto_faq.html#move-the-edge-of-an-axes-to-make-room-for-tick-labels
Automatically make room for tick labels
https://matplotlib.org/faq/howto_faq.html#automatically-make-room-for-tick-labels
Fig size
MetPy Mondays '#128 - Sizing Figures for Publication : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-128-sizing-figures
Figures - American Meteorological Society
https://www.ametsoc.org/ams/index.cfm/publications/authors/journal-and-bams-authors/figure-information-for-authors/
DPI
code:python
# When figure is created
fig,ax=plt.subplots(figuresize=(12,10),dpi=3000)
# Set parameters globally for all figures
plt.rcParams"figure.dpi" = 300
# when saving a figure
plt.savefig("foo.png",dpi=300)
Title
How to customize titles in Matplotlib
#The Python Graph Gallery
/icons/hr.icon
Making Subplot
subplot
make subplot once at a time
subplots
make subplots all at once
subplot2grid()
Create an axis at specific location inside a regular grid.
subplot
MetPy Mondays #36 - matplotlib subplots : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/en/entry/matplotlib-subplots
code:python
plt.subplot(3,1,1)
plt.subplot(3,1,2)
plt.subplot(3,1,3)
subplots
prepare subplots
MetPy Mondays #101 - Making Subplots the Smart Way! : Unidata Developer's Blog
#MetPy Mondays
only 1 subplot
code:python
fig, ax = plt.subplots()
with Cartopy
code:python
fig,axes=plt.subplots(3,3,figsize=8.27,11.69,subplot_kw={'projection': ccrs.PlateCarree()})
flatten axes
code:python
fig,axes=plt.subplots(3,3)
axes=axes.flatten()
flatten axes
code:python
for ax, df_key in zip(axes.flatten(), imputations):
....
remove last subplot
code:python
axlast=axes-1
axlast.remove()
MetPy Mondays '#102: Using Dictionaries to Store Plotting Parameters : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-102-using-dictionaries
MetPy Mondays `#103 - Config Files and configparser : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-103-config-files
MetPy Mondays `#124 - Aligning Labels in Matplotlib : Unidata Developer's Blog
code:python
fig.align_labels()
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-124-aligning-labels
Align y-labels
https://matplotlib.org/gallery/pyplots/align_ylabels.html
MetPy Mondays `#118 - Legends and Subplots : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-118-legends-and
Examples on google collaboratory
https://colab.research.google.com/drive/154TGVX6UzLBkgOsTuv1fcbbPypv8kTpx
GridSpec
Customizing Location of Subplot Using GridSpec
Example
MetPy Mondays #327 — Complicated Layouts with GridSpec : Unidata Developer's Blog
AxesGrid
Overview of AxesGrid toolkit
Demo Axes Grid
subplot_mosaic
Complex and semantic figure composition (subplot_mosaic) — Matplotlib documentation
Simplifying subplots creation in Matplotlib | by Parul Pandey | May, 2023 | Towards Data Science
/icons/hr.icon
Adjust Subplots
subplots_adjust
pylab_examples example code: subplots_adjust.py
Tight Layout
Tight Layout guide
Constrained Layout
Constrained Layout Guide — Matplotlib documentation
The constrained layout and tight layout are two options available for layout management in Matplotlib. Constrained layout automatically adjusts the positions of subplots to fit their contents within the figure while avoiding overlaps. This is useful for creating complex plots with multiple subplots that would otherwise require manual adjustments.
On the other hand, tight layout adjusts the spacing between subplots to fit them within the figure without overlapping. However, this can sometimes result in elements being pushed too close, making them difficult to read.
In general, constrained layout is recommended when working with complex plots with multiple subplots, while tight layout may be more appropriate for simpler plots where readability is a priority. Ultimately, the choice between these two options depends on the specific needs of the visualization and the personal preferences of the user.
/icons/hr.icon
Inset Axes
Zoom region inset axes
https://matplotlib.org/gallery/subplots_axes_and_figures/zoom_inset_axes.html
MetPy Mondays `#120 - Inset Axes with RADAR data : Unidata Developer's Blog
https://www.unidata.ucar.edu/blogs/developer/entry/metpy-mondays-120-inset-axes
python - Cartopy coastlines hidden by inset_axes use of Axes.pie - Stack Overflow
https://stackoverflow.com/questions/44200931/cartopy-coastlines-hidden-by-inset-axes-use-of-axes-pie
python - embed small map (cartopy) on matplotlib figure - Stack Overflow
https://stackoverflow.com/questions/55385515/embed-small-map-cartopy-on-matplotlib-figure
hr.icon
Examples
python - matplotlib write text in the margin - Stack Overflow
https://stackoverflow.com/questions/5464315/matplotlib-write-text-in-the-margin
Matplotlib の多くのサブプロットでサブプロットのサイズまたは間隔を改善する方法 | Delft スタック
https://www.delftstack.com/ja/howto/matplotlib/how-to-improve-subplot-size-or-spacing-with-many-subplots-in-matplotlib/
See also
matplotlib colorbar
matplotlib axis
matplotlib style