Repository: matplotlib/matplotlib
File: lib/matplotlib/figure.py (Python)

Code before:
            If `True`, then convert from inches to figure relative.
        """
        if not isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
            return None, None, None, None
        info = self.get_layout_engine().get()
        w_pad = info['w_pad']
        h_pad = info['h_pad']
        wspace = info['wspace']
        hspace = info['hspace']

        if relative and (w_pad is not None or h_pad is not None):
            renderer = self._get_renderer()
            dpi = renderer.dpi
            w_pad = w_pad * dpi / renderer.width
            h_pad = h_pad * dpi / renderer.height

        return w_pad, h_pad, wspace, hspace

    def _set_base_canvas(self):
        """
        Initialize self.canvas with a FigureCanvasBase instance.

        This is used upon initialization of the Figure, but also
        to reset the canvas when decoupling from pyplot.
        """
        # check if we have changed the API due to hi-dpi screens
        orig_dpi = getattr(self, '_original_dpi', self._dpi)
        FigureCanvasBase(self)  # Set self.canvas as a side-effect
        # put it back to what it was
        if orig_dpi != self._dpi:
            self.dpi = orig_dpi

    def set_canvas(self, canvas):
        """
        Set the canvas that contains the figure

        Parameters
        ----------
        canvas : FigureCanvas
        """
        self.canvas = canvas

    @_docstring.interpd
    def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
                 vmin=None, vmax=None, origin=None, resize=False, *,
                 colorizer=None, **kwargs):
        """
        Add a non-resampled image to the figure.

        The image is attached to the lower or upper left corner depending on
        *origin*.

Review comment (suggestion):
```suggestion
        # check if we have changed the DPI due to hi-dpi screens
```

Code after:
            If `True`, then convert from inches to figure relative.
        """
        if not isinstance(self.get_layout_engine(), ConstrainedLayoutEngine):
            return None, None, None, None
        info = self.get_layout_engine().get()
        w_pad = info['w_pad']
        h_pad = info['h_pad']
        wspace = info['wspace']
        hspace = info['hspace']

        if relative and (w_pad is not None or h_pad is not None):
            renderer = self._get_renderer()
            dpi = renderer.dpi
            w_pad = w_pad * dpi / renderer.width
            h_pad = h_pad * dpi / renderer.height

        return w_pad, h_pad, wspace, hspace

    def _set_base_canvas(self):
        """
        Initialize self.canvas with a FigureCanvasBase instance.

        This is used upon initialization of the Figure, but also
        to reset the canvas when decoupling from pyplot.
        """
        # check if we have changed the DPI due to hi-dpi screens
        orig_dpi = getattr(self, '_original_dpi', self._dpi)
        FigureCanvasBase(self)  # Set self.canvas as a side-effect
        # put it back to what it was
        if orig_dpi != self._dpi:
            self.dpi = orig_dpi

    def set_canvas(self, canvas):
        """
        Set the canvas that contains the figure

        Parameters
        ----------
        canvas : FigureCanvas
        """
        self.canvas = canvas

    @_docstring.interpd
    def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
                 vmin=None, vmax=None, origin=None, resize=False, *,
                 colorizer=None, **kwargs):
        """
        Add a non-resampled image to the figure.

        The image is attached to the lower or upper left corner depending on
        *origin*.