4141import matplotlib .transforms as mtransforms
4242import matplotlib .gridspec as mgridspec
4343from numbers import Integral
44+ from matplotlib import docstring
4445from matplotlib .gridspec import SubplotSpec
4546try :
4647 import matplotlib .backends .backend_macosx as mbackend
5051from .utils import _notNone , _counter , units
5152from . import projs , axes
5253__all__ = [
53- 'axes_grid' , 'close' , 'show' , 'subplots' , 'Figure' , 'GridSpec' ,
54+ 'axes_grid' , 'close' , 'figure' , ' show' , 'subplots' , 'Figure' , 'GridSpec' ,
5455 ]
5556
5657# Translation
@@ -704,56 +705,57 @@ def __exit__(self, *args):
704705 for label in self ._labels :
705706 label .set_visible (True )
706707
708+ # TODO: obfuscate Figure call signature like with axes methods?
709+ figure_kwargs = """
710+ tight : bool, optional
711+ Toggles automatic tight layout adjustments. Default is
712+ :rc:`tight`.
713+ pad : float or str, optional
714+ Padding around edge of figure. Units are interpreted by
715+ `~proplot.utils.units`. Default is :rc:`subplots.pad`.
716+ axpad : float or str, optional
717+ Padding between subplots in adjacent columns and rows. Units are
718+ interpreted by `~proplot.utils.units`. Default is
719+ :rc:`subplots.axpad`.
720+ panelpad : float or str, optional
721+ Padding between subplots and axes panels, and between "stacked"
722+ panels. Units are interpreted by `~proplot.utils.units`.Default is
723+ :rc:`subplots.panelpad`.
724+ includepanels : bool, optional
725+ Whether to include panels when centering *x* axis labels,
726+ *y* axis labels, and figure "super titles" along the edge of the
727+ subplot grid. Default is ``False``.
728+ autoformat : bool, optional
729+ Whether to automatically configure *x* axis labels, *y* axis
730+ labels, axis formatters, axes titles, colorbar labels, and legend
731+ labels when a `~pandas.Series`, `~pandas.DataFrame` or
732+ `~xarray.DataArray` with relevant metadata is passed to a plotting
733+ command.
734+ """
735+ docstring .interpd .update (figure_kwargs = figure_kwargs .strip ())
736+
707737class Figure (mfigure .Figure ):
708738 """The `~matplotlib.figure.Figure` class returned by `subplots`. At
709739 draw-time, an improved tight layout algorithm is employed, and
710740 the space around the figure edge, between subplots, and between
711741 panels is changed to accommodate subplot content. Figure dimensions
712742 may be automatically scaled to preserve subplot aspect ratios."""
743+ @docstring .dedent_interpd
713744 def __init__ (self ,
714745 tight = None ,
715746 pad = None , axpad = None , panelpad = None , includepanels = False ,
716- autoformat = True ,
717- ref = 1 , order = 'C' , # documented in subplots but needed here
747+ autoformat = True , ref_num = 1 , # ref_num should never change
718748 subplots_kw = None , gridspec_kw = None , subplots_orig_kw = None ,
719749 tight_layout = None , constrained_layout = None ,
720750 ** kwargs ):
721751 """
722752 Parameters
723753 ----------
724- tight : bool, optional
725- Toggles automatic tight layout adjustments. Default is
726- :rc:`tight`.
727- pad : float or str, optional
728- Padding around edge of figure. Units are interpreted by
729- `~proplot.utils.units`. Default is :rc:`subplots.pad`.
730- axpad : float or str, optional
731- Padding between subplots in adjacent columns and rows. Units are
732- interpreted by `~proplot.utils.units`. Default is
733- :rc:`subplots.axpad`.
734- panelpad : float or str, optional
735- Padding between subplots and axes panels, and between "stacked"
736- panels. Units are interpreted by `~proplot.utils.units`.Default is
737- :rc:`subplots.panelpad`.
738- includepanels : bool, optional
739- Whether to include panels when centering *x* axis labels,
740- *y* axis labels, and figure "super titles" along the edge of the
741- subplot grid. Default is ``False``.
742- autoformat : bool, optional
743- Whether to automatically configure *x* axis labels, *y* axis
744- labels, axis formatters, axes titles, colorbar labels, and legend
745- labels when a `~pandas.Series`, `~pandas.DataFrame` or
746- `~xarray.DataArray` with relevant metadata is passed to a plotting
747- command.
754+ %(figure_kwargs)s
748755 gridspec_kw, subplots_kw, subplots_orig_kw
749756 Keywords used for initializing the main gridspec, for initializing
750757 the figure, and original spacing keyword args used for initializing
751758 the figure that override tight layout spacing.
752-
753- Other parameters
754- ----------------
755- ref, order
756- Documented in `subplots`.
757759 tight_layout, constrained_layout
758760 Ignored, because ProPlot uses its own tight layout algorithm.
759761 **kwargs
@@ -771,7 +773,6 @@ def __init__(self,
771773 self ._auto_format = autoformat
772774 self ._auto_tight_layout = _notNone (tight , rc ['tight' ])
773775 self ._include_panels = includepanels
774- self ._order = order # used for configuring panel axes_grids
775776 self ._ref_num = ref
776777 self ._axes_main = []
777778 self ._subplots_orig_kw = subplots_orig_kw
@@ -1709,7 +1710,7 @@ def _iter_axes(self):
17091710 return axs
17101711
17111712#-----------------------------------------------------------------------------#
1712- # Primary plotting function, used to create figure/ axes
1713+ # Primary functions used to create figures and axes
17131714#-----------------------------------------------------------------------------#
17141715def _journals (journal ):
17151716 """Journal sizes for figures."""
@@ -1766,6 +1767,26 @@ def _axes_dict(naxs, value, kw=False, default=None):
17661767 raise ValueError (f'Have { naxs } axes, but { value } has properties for axes { ", " .join (str (i ) for i in sorted (kwargs .keys ()))} .' )
17671768 return kwargs
17681769
1770+ # TODO: Figure out how to save subplots keyword args!
1771+ @docstring .dedent_interpd
1772+ def figure (** kwargs ):
1773+ """
1774+ Analogous to `matplotlib.pyplot.figure`, creates an empty figure meant
1775+ to be filled with axes using `Figure.add_subplot`.
1776+
1777+ Parameters
1778+ ----------
1779+ %(figure_kwargs)s
1780+ **kwargs
1781+ Passed to `~matplotlib.figure.Figure`.
1782+ """
1783+ # TODO: Repair subplots-dependent behavior! Permit serial args!
1784+ kwargs ['gridspec_kw' ] = None
1785+ kwargs ['subplots_kw' ] = None
1786+ kwargs ['subplots_orig_kw' ] = None
1787+ return plt .figure (FigureClass = Figure , ** kwargs )
1788+
1789+ @docstring .dedent_interpd
17691790def subplots (array = None , ncols = 1 , nrows = 1 ,
17701791 ref = 1 , order = 'C' ,
17711792 aspect = 1 , figsize = None ,
@@ -1922,23 +1943,7 @@ def subplots(array=None, ncols=1, nrows=1,
19221943
19231944 Other parameters
19241945 ----------------
1925- tight : bool, optional
1926- Toggles automatic tight layout adjustments. Default is
1927- :rc:`tight`.
1928-
1929- If you manually specify a spacing, it will be used
1930- to override the tight layout spacing -- for example, with ``left=0.1``,
1931- the left margin is set to 0.1 inches wide, while the remaining margin
1932- widths are calculated automatically.
1933- pad, axpad, panelpad : float or str, optional
1934- Padding for automatic tight layout adjustments. See `Figure` for
1935- details.
1936- includepanels : bool, optional
1937- Whether to include panels when calculating the position of certain
1938- spanning labels. See `Figure` for details.
1939- autoformat : bool, optional
1940- Whether to automatically format axes when special datasets are
1941- passed to plotting commands. See `Figure` for details.
1946+ %(figure_kwargs)s
19421947
19431948 Returns
19441949 -------
@@ -2120,7 +2125,8 @@ def subplots(array=None, ncols=1, nrows=1,
21202125 wratios = wratios , hratios = hratios , wspace = wspace , hspace = hspace ,
21212126 wpanels = ['' ]* ncols , hpanels = ['' ]* nrows ,
21222127 )
2123- fig = plt .figure (FigureClass = Figure , tight = tight , figsize = figsize , ref = ref ,
2128+ fig = plt .figure (FigureClass = Figure , tight = tight , figsize = figsize ,
2129+ ref_num = ref ,
21242130 pad = pad , axpad = axpad , panelpad = panelpad , autoformat = autoformat ,
21252131 includepanels = includepanels ,
21262132 subplots_orig_kw = subplots_orig_kw , subplots_kw = subplots_kw ,
0 commit comments