tacaswell.github.io - Casthoughts

Description: Blog of Thomas A Caswell

Example domain paragraphs

Dynamically adding Axes to a Figure

At the prompting of a user on Matplotlib’s gitter channel I wrote the following example:

import matplotlib.pyplot as plt import numpy as np from itertools import count from matplotlib.gridspec import GridSpec def reflow_gen ( fig ): # we own this figure now so clear it fig . clf () # running count of the number of axes axcount = count ( 1 ) # the shape of the grid row_guess = col_guess = 0 # the current GridSpec object gs = None # we are a generator, so loop forever while True : # what number is this Axes? j = next ( axcount ) # do we need to re-flow? if j > row_guess * col_guess : # Find the s