@@ -764,7 +764,8 @@ def _add_axes_internal(self, ax, key):
764764 return ax
765765
766766 def subplots (self , nrows = 1 , ncols = 1 , * , sharex = False , sharey = False ,
767- squeeze = True , subplot_kw = None , gridspec_kw = None ):
767+ squeeze = True , width_ratios = None , height_ratios = None ,
768+ subplot_kw = None , gridspec_kw = None ):
768769 """
769770 Add a set of subplots to this figure.
770771
@@ -807,6 +808,18 @@ def subplots(self, nrows=1, ncols=1, *, sharex=False, sharey=False,
807808 is always a 2D array containing Axes instances, even if it ends
808809 up being 1x1.
809810
811+ width_ratios : array-like of length *ncols*, optional
812+ Defines the relative widths of the columns. Each column gets a
813+ relative width of ``width_ratios[i] / sum(width_ratios)``.
814+ If not given, all columns will have the same width. Equivalent
815+ to ``gridspec_kw={'width_ratios': [...]}``.
816+
817+ height_ratios : array-like of length *nrows*, optional
818+ Defines the relative heights of the rows. Each row gets a
819+ relative height of ``height_ratios[i] / sum(height_ratios)``.
820+ If not given, all rows will have the same height. Equivalent
821+ to ``gridspec_kw={'height_ratios': [...]}``.
822+
810823 subplot_kw : dict, optional
811824 Dict with keywords passed to the `.Figure.add_subplot` call used to
812825 create each subplot.
@@ -871,6 +884,17 @@ def subplots(self, nrows=1, ncols=1, *, sharex=False, sharey=False,
871884 """
872885 if gridspec_kw is None :
873886 gridspec_kw = {}
887+ if height_ratios is not None :
888+ if 'height_ratios' in gridspec_kw :
889+ raise ValueError ("'height_ratios' must not be defined both as "
890+ "parameter and as key in 'gridspec_kw'" )
891+ gridspec_kw ['height_ratios' ] = height_ratios
892+ if width_ratios is not None :
893+ if 'width_ratios' in gridspec_kw :
894+ raise ValueError ("'width_ratios' must not be defined both as "
895+ "parameter and as key in 'gridspec_kw'" )
896+ gridspec_kw ['width_ratios' ] = width_ratios
897+
874898 gs = self .add_gridspec (nrows , ncols , figure = self , ** gridspec_kw )
875899 axs = gs .subplots (sharex = sharex , sharey = sharey , squeeze = squeeze ,
876900 subplot_kw = subplot_kw )
@@ -1683,7 +1707,8 @@ def _normalize_grid_string(layout):
16831707 return [list (ln ) for ln in layout .strip ('\n ' ).split ('\n ' )]
16841708
16851709 def subplot_mosaic (self , mosaic , * , sharex = False , sharey = False ,
1686- subplot_kw = None , gridspec_kw = None , empty_sentinel = '.' ):
1710+ width_ratios = None , height_ratios = None ,
1711+ empty_sentinel = '.' , subplot_kw = None , gridspec_kw = None ):
16871712 """
16881713 Build a layout of Axes based on ASCII art or nested lists.
16891714
@@ -1739,6 +1764,18 @@ def subplot_mosaic(self, mosaic, *, sharex=False, sharey=False,
17391764 units behave as for `subplots`. If False, each subplot's x- or
17401765 y-axis will be independent.
17411766
1767+ width_ratios : array-like of length *ncols*, optional
1768+ Defines the relative widths of the columns. Each column gets a
1769+ relative width of ``width_ratios[i] / sum(width_ratios)``.
1770+ If not given, all columns will have the same width. Equivalent
1771+ to ``gridspec_kw={'width_ratios': [...]}``.
1772+
1773+ height_ratios : array-like of length *nrows*, optional
1774+ Defines the relative heights of the rows. Each row gets a
1775+ relative height of ``height_ratios[i] / sum(height_ratios)``.
1776+ If not given, all rows will have the same height. Equivalent
1777+ to ``gridspec_kw={'height_ratios': [...]}``.
1778+
17421779 subplot_kw : dict, optional
17431780 Dictionary with keywords passed to the `.Figure.add_subplot` call
17441781 used to create each subplot.
@@ -1763,6 +1800,17 @@ def subplot_mosaic(self, mosaic, *, sharex=False, sharey=False,
17631800 """
17641801 subplot_kw = subplot_kw or {}
17651802 gridspec_kw = gridspec_kw or {}
1803+ if height_ratios is not None :
1804+ if 'height_ratios' in gridspec_kw :
1805+ raise ValueError ("'height_ratios' must not be defined both as "
1806+ "parameter and as key in 'gridspec_kw'" )
1807+ gridspec_kw ['height_ratios' ] = height_ratios
1808+ if width_ratios is not None :
1809+ if 'width_ratios' in gridspec_kw :
1810+ raise ValueError ("'width_ratios' must not be defined both as "
1811+ "parameter and as key in 'gridspec_kw'" )
1812+ gridspec_kw ['width_ratios' ] = width_ratios
1813+
17661814 # special-case string input
17671815 if isinstance (mosaic , str ):
17681816 mosaic = self ._normalize_grid_string (mosaic )
0 commit comments