Skip to content

Instantly share code, notes, and snippets.

@r0oland
Last active March 22, 2024 10:25
Show Gist options
  • Save r0oland/4e37f72730715ab602994549648ef1c0 to your computer and use it in GitHub Desktop.
Save r0oland/4e37f72730715ab602994549648ef1c0 to your computer and use it in GitHub Desktop.
Python Plotting
# see https://matplotlib.org/stable/gallery/subplots_axes_and_figures/mosaic.html#sphx-glr-gallery-subplots-axes-and-figures-mosaic-py
DPI = 100
Y_HEIGHT = 800
X_WIDTH = 1000
fig = plt.figure(figsize=(X_WIDTH/DPI, Y_HEIGHT/DPI), dpi=DPI)
axDict = fig.subplot_mosaic(
[
["a", "b"],
["c", "d"],
],
)
# get list of keys we can iterate over
axKeys = list(axDict.keys())
# ith_element = axKeys[i]
axDict["a"].bar(["a", "b", "c"], [5, 7, 9])
axDict["b"].plot([1, 2, 3])
axDict["c"].hist([5, 7, 9])
axDict["d"].imshow([[1, 2], [2, 1]])
# or
ax = axDict[axKeys[0]]
ax.bar(["a", "b", "c"], [5, 7, 9])
# etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment