Created
March 3, 2017 18:04
-
-
Save golobor/1495785d083b3e237f56ee39e9697f18 to your computer and use it in GitHub Desktop.
making grids of plots in units that make sense
This file contains 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
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