Created
August 19, 2021 15:03
-
-
Save mtrebitsch/189509d325635164f0aec4c7187bbdcf to your computer and use it in GitHub Desktop.
Testing the subplot_mosaic feature from matplotlib 3.3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
# Helper function used for visualization in the following examples | |
def identify_axes(ax_dict, fontsize=48): | |
""" | |
Helper to identify the Axes in the examples below. | |
Draws the label in a large font in the center of the Axes. | |
Parameters | |
---------- | |
ax_dict : dict[str, Axes] | |
Mapping between the title / label and the Axes. | |
fontsize : int, optional | |
How big the label should be. | |
""" | |
kw = dict(ha="center", va="center", fontsize=fontsize, color="darkgrey") | |
for k, ax in ax_dict.items(): | |
ax.text(0.5, 0.5, k, transform=ax.transAxes, **kw) | |
# Create and fill the index array | |
mosaic = np.zeros((5, 5), dtype=int) | |
iu1 = np.triu_indices(5) | |
mosaic[iu1] = np.arange(iu1[0].size)+1 | |
# Create the subplots | |
axd = plt.figure(constrained_layout=True).subplot_mosaic(mosaic, empty_sentinel=0) | |
# This is just for the visual aid and can be safely removed | |
identify_axes(axd) | |
# Plotting with each subplot | |
x = np.linspace(0, 10, 100) | |
for i in range(15): | |
axd[i+1].plot(x, x**(i+1)) | |
plt.savefig('test.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment