spacepy.plot.collapse_vertical

spacepy.plot.collapse_vertical(combine, others=(), leave_axis=False)[source]

Collapse the vertical spacing between two or more subplots.

Useful for a multi-panel plot where most subplots should have space between them but several adjacent ones should not (i.e., appear as a single plot.) This function will remove all the vertical space between the subplots listed in combine and redistribute the space between all of the subplots in both combine and others in proportion to their current size, so that the relative size of the subplots does not change.

Parameters:
combinesequence

The Axes objects (i.e. subplots) which should be placed together with no vertical space.

Other Parameters:
otherssequence

The Axes objects (i.e. subplots) which will keep their vertical spacing, but will be expanded with the space taken away from between the elements of combine.

leave_axisbool

If set to true, will leave the axis lines and tick marks between the collapsed subplots. By default, the axis line (“spine”) is removed so the two subplots appear as one.

Notes

This function can be fairly fragile and should only be used for fairly simple layouts, e.g., a one-column multi-row plot stack.

This may require some clean-up of the y axis labels, as they are likely to overlap.

Examples

>>> import spacepy.plot.utils
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> #Make three stacked subplots
>>> ax0 = fig.add_subplot(311)
>>> ax1 = fig.add_subplot(312)
>>> ax2 = fig.add_subplot(313)
>>> ax0.plot([1, 2, 3], [1, 2, 1]) #just make some lines
[<matplotlib.lines.Line2D object at 0x0000000>]
>>> ax1.plot([1, 2, 3], [1, 2, 1])
[<matplotlib.lines.Line2D object at 0x0000000>]
>>> ax2.plot([1, 2, 3], [1, 2, 1])
[<matplotlib.lines.Line2D object at 0x0000000>]
>>> #Collapse space between top two plots, leave bottom one alone
>>> spacepy.plot.utils.collapse_vertical([ax0, ax1], [ax2])

(Source code, png, hires.png, pdf)

../_images/spacepy-plot-collapse_vertical-1.png