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

Code before:

    def get_window_extent(self, renderer=None):
        """
        Get the artist's bounding box in display space.

        The bounding box's width and height are non-negative.

        Subclasses should override for inclusion in the bounding box
        "tight" calculation. Default is to return an empty bounding
        box at 0, 0.

        .. warning ::

          Be careful when using this function, the results will not update if
          the artist window extent of the artist changes.

          The extent can change due to any changes in the transform stack, such
          as changing the Axes limits, the figure size, the canvas used (as is
          done when saving a figure), or the DPI.

          This can lead to unexpected behavior where interactive figures will
          look fine on the screen, but will save incorrectly.

          To get accurate results you may need to manually call
          `matplotlib.figure.Figure.savefig` or
          `matplotlib.figure.Figure.draw_without_rendering` to have Matplotlib
          compute the rendered size.

        """
        return Bbox([[0, 0], [0, 0]])

    def get_tightbbox(self, renderer=None):
        """
        Like `.Artist.get_window_extent`, but includes any clipping.

        Parameters
        ----------
        renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
            renderer that will be used to draw the figures (i.e.
            ``fig.canvas.get_renderer()``)

        Returns
        -------
        `.Bbox` or None
            The enclosing bounding box (in figure pixel coordinates).
            Returns None if clipping results in no intersection.
        """
        bbox = self.get_window_extent(renderer)
        if self.get_clip_on():
            clip_box = self.get_clip_box()
            if clip_box is not None:

Review comment (bug):
This is unclear to me. I feel, we are mixing two things here an it's too short to understand:

1. `draw_without_rendering` ensures the window_extent is up-to-date for the current transform stack. This resolves incorrect intermediate state due to lazy evalutation, e.g. of the layout.
2. How does `savefig` help here? Is this this the double save idea of https://github.com/matplotlib/matplotlib/issues/2831#issuecomment-2799571987. If so, that needs more explanation. Also I'm not sure on the generality of the solution https://github.com/matplotlib/matplotlib/issues/2831#issuecomment-2799852381.

Code after:

    def get_window_extent(self, renderer=None):
        """
        Get the artist's bounding box in display space.

        The bounding box's width and height are non-negative.

        Subclasses should override for inclusion in the bounding box
        "tight" calculation. Default is to return an empty bounding
        box at 0, 0.

        .. warning::

          The extent can change due to any changes in the transform stack, such
          as changing the Axes limits, the figure size, the canvas used (as is
          done when saving a figure), or the DPI.

          Relying on a once-retrieved window extent can lead to unexpected
          behavior in various cases such as interactive figures being resized or
          moved to a screen with different dpi, or figures that look fine on
          screen render incorrectly when saved to file.

          To get accurate results you may need to manually call
          `matplotlib.figure.Figure.savefig` or
          `matplotlib.figure.Figure.draw_without_rendering` to have Matplotlib
          compute the rendered size.

        """
        return Bbox([[0, 0], [0, 0]])

    def get_tightbbox(self, renderer=None):
        """
        Like `.Artist.get_window_extent`, but includes any clipping.

        Parameters
        ----------
        renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
            renderer that will be used to draw the figures (i.e.
            ``fig.canvas.get_renderer()``)

        Returns
        -------
        `.Bbox` or None
            The enclosing bounding box (in figure pixel coordinates).
            Returns None if clipping results in no intersection.
        """
        bbox = self.get_window_extent(renderer)
        if self.get_clip_on():
            clip_box = self.get_clip_box()
            if clip_box is not None:
                bbox = Bbox.intersection(bbox, clip_box)