Skip to content

Instantly share code, notes, and snippets.

@golobor
Created March 3, 2017 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save golobor/1495785d083b3e237f56ee39e9697f18 to your computer and use it in GitHub Desktop.
Save golobor/1495785d083b3e237f56ee39e9697f18 to your computer and use it in GitHub Desktop.
making grids of plots in units that make sense
def gridspec_inches(
wcols,
hrows,
fig_kwargs={}):
import matplotlib as mpl
import matplotlib.pyplot as plt
fig_height_inches = (
sum(hrows)
)
fig_width_inches = (
sum(wcols)
)
fig=plt.figure(
figsize=(fig_width_inches,fig_height_inches),
subplotpars=mpl.figure.SubplotParams(
left=0,
right=1,
bottom=0,
top=1,
wspace =0,
hspace = 0.0),
frameon=False,
**fig_kwargs)
fig.set_size_inches(fig_width_inches,fig_height_inches,forward=True)
gs = mpl.gridspec.GridSpec(
len(hrows),
len(wcols),
left=0,
right=1,
top=1,
bottom=0,
wspace=0,
hspace=0,
width_ratios=wcols,
height_ratios=hrows
)
return fig, gs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment