atompy.make_me_nice#
- atompy.make_me_nice(fig=None, fix_figwidth=True, margin_pad_pts=5.0, margin_pad_ignores_labels=False, col_pad_pts=10.0, col_pad_ignores_labels=False, row_pad_pts=10.0, row_pad_ignores_labels=False, max_figwidth=inf, nruns=2, renderer=None)[source]#
Optimize whitespace in the figure.
Re-arange axes in fig such that their margins don’t overlap. Also change margins at the edges of the figure such that everything fits. Trim or expand the figure height accordingly.
Advantages over
matplotlib.pyplot.tight_layoutor constrained layout:Keeps widths constant (either of the axes or of the figure).
Handle colorbars as one may expect (if they were added using
add_colorbar()).Updates figure height to optimize white-space for fixed aspect ratios.
Disadvantages:
Can only handle nrows times ncols grids. If you have anything fancy (an axes that spans multiple columns), you cannot use this straightforwardly.
- Parameters:
- fig
matplotlib.figure.Figure, optional If
None, use last active figure.- fix_figwidthbool, default
True Configure if the figure width is kept constant or not.
True:Keep the figure width constant and scale all axes-widths accordingly.
False:Keep axes widths constant and scale figure width accordingly. Also note the max_figwidth parameter.
- margin_pad_ptsarray_like, default
5.0 Extra padding for the figure edges in pts.
- float:
Same padding for left, right, top, bottom edge.
- (float, float, float, float):
Different padding for left, right, top, bottom edge.
- margin_pad_ignores_labelsarray_like, default
False Boolean controlling if
margin_pad_ptsshould add padding taking into account axes labels or not.- bool:
Switch behavior for all margins left, right, top, bottom.
- (bool, bool):
Switch behavior for (left, right) and (top, bottom) separately.
- (bool, bool, bool, bool)
Switch behavior for left, right, top, bottom margins separately.
- col_pad_pts, row_pad_ptsarray_like, default
10.0 Extra padding between the columns (rows) in pts.
- float:
Same padding in-between all columns (rows).
- (float, …):
Different values in-between all columns. Must have a length of
ncols-1(nrows-1).
- col_pad_ignores_labels, row_pad_ignores_labelsarray_like, default
False Boolean controlling if the padding in-between columns (rows) of axes should ignore axes labels or not.
- bool:
Global for all columns (rows).
- (bool, …):
Different choices for each column (row). Must have a length of
ncols-1(nrows-1).
- max_figwidth
float, defaultnumpy.inf Only relevant if
fix_figwidth == False.Maximum figure width in inches. Throws
FigureWidthTooLargeErrorif the new figure width exceeds this value.- nruns
int, default2 Number of times the algorithm runs.
If your axes change significantly in size, different ticklabels may be drawn which may change the size of the axes. To account for this,
make_me_nicehas to run another time.If the margins produced by
make_me_niceare wrong, increasing the number of runs may help.- renderer
matplotlib.backend_bases.RendererBase, optional The renderer used to draw the figure.
Generally not necessary to pass it. If, however, you use a backend that takes a long time to render (e.g., a LuaLaTeX pgf backend), it may increase performance by passing the renderer. Use
get_renderer()to get your current renderer.
- fig
Notes
Cannot handle fancy
matplotlib.gridspec.GridSpecs, e.g., where one subplot spans multiple other subplots. If you need one of those, you’re on your own.If you have subplots with different aspect ratios and fig_width is not
None, the positioning of the subplots may be incorrect (e.g., off-centered in the column). Usealign_axes_vertically()oralign_axes_horizontally()to fix that.If you use a different backend in plt.savefig than the default, you need to specify that before creating the figure. E.g., with
matplotlib.use("some-backend").