Ejemplo n.º 1
0
 def __init__(self,
              nrows,
              ncols,
              subplot_spec,
              wspace=None,
              hspace=None,
              height_ratios=None,
              width_ratios=None):
     """
     The number of rows and number of columns of the grid need to
     be set. An instance of SubplotSpec is also needed to be set
     from which the layout parameters will be inherited. The wspace
     and hspace of the layout can be optionally specified or the
     default values (from the figure or rcParams) will be used.
     """
     self._wspace = wspace
     self._hspace = hspace
     self._subplot_spec = subplot_spec
     self.figure = self._subplot_spec.get_gridspec().figure
     super().__init__(nrows,
                      ncols,
                      width_ratios=width_ratios,
                      height_ratios=height_ratios)
     # do the layoutgrids for constrained_layout:
     subspeclb = subplot_spec.get_gridspec()._layoutgrid
     if subspeclb is None:
         self._layoutgrid = None
     else:
         # this _toplayoutbox is a container that spans the cols and
         # rows in the parent gridspec.  Not yet implemented,
         # but we do this so that it is possible to have subgridspec
         # level artists.
         self._toplayoutgrid = layoutgrid.LayoutGrid(
             parent=subspeclb,
             name=subspeclb.name + '.top' + layoutgrid.seq_id(),
             nrows=1,
             ncols=1,
             parent_pos=(subplot_spec.rowspan, subplot_spec.colspan))
         self._layoutgrid = layoutgrid.LayoutGrid(
             parent=self._toplayoutgrid,
             name=(self._toplayoutgrid.name + '.gridspec' +
                   layoutgrid.seq_id()),
             nrows=nrows,
             ncols=ncols,
             width_ratios=width_ratios,
             height_ratios=height_ratios)
Ejemplo n.º 2
0
    def __init__(self, nrows, ncols, figure=None,
                 left=None, bottom=None, right=None, top=None,
                 wspace=None, hspace=None,
                 width_ratios=None, height_ratios=None):
        """
        Parameters
        ----------
        nrows, ncols : int
            The number of rows and columns of the grid.

        figure : `~.figure.Figure`, optional
            Only used for constrained layout to create a proper layoutgrid.

        left, right, top, bottom : float, optional
            Extent of the subplots as a fraction of figure width or height.
            Left cannot be larger than right, and bottom cannot be larger than
            top. If not given, the values will be inferred from a figure or
            rcParams at draw time. See also `GridSpec.get_subplot_params`.

        wspace : float, optional
            The amount of width reserved for space between subplots,
            expressed as a fraction of the average axis width.
            If not given, the values will be inferred from a figure or
            rcParams when necessary. See also `GridSpec.get_subplot_params`.

        hspace : float, optional
            The amount of height reserved for space between subplots,
            expressed as a fraction of the average axis height.
            If not given, the values will be inferred from a figure or
            rcParams when necessary. See also `GridSpec.get_subplot_params`.

        width_ratios : array-like of length *ncols*, optional
            Defines the relative widths of the columns. Each column gets a
            relative width of ``width_ratios[i] / sum(width_ratios)``.
            If not given, all columns will have the same width.

        height_ratios : array-like of length *nrows*, optional
            Defines the relative heights of the rows. Each column gets a
            relative height of ``height_ratios[i] / sum(height_ratios)``.
            If not given, all rows will have the same height.

        """
        self.left = left
        self.bottom = bottom
        self.right = right
        self.top = top
        self.wspace = wspace
        self.hspace = hspace
        self.figure = figure

        super().__init__(nrows, ncols,
                         width_ratios=width_ratios,
                         height_ratios=height_ratios)

        # set up layoutgrid for constrained_layout:
        self._layoutgrid = None
        if self.figure is None or not self.figure.get_constrained_layout():
            self._layoutgrid = None
        else:
            self._toplayoutbox = self.figure._layoutgrid
            self._layoutgrid = layoutgrid.LayoutGrid(
                parent=self.figure._layoutgrid,
                parent_inner=True,
                name=(self.figure._layoutgrid.name + '.gridspec' +
                      layoutgrid.seq_id()),
                ncols=ncols, nrows=nrows, width_ratios=width_ratios,
                height_ratios=height_ratios)