Repository: matplotlib/matplotlib
File: lib/matplotlib/backends/backend_agg.py (Python)

Code before:
                        f"= {path.simplify_threshold} "
                        "on the input)."
                        )
                    if nmax > 100:
                        msg = (
                            "Exceeded cell block limit in Agg.  Please reduce "
                            "the value of rcParams['agg.path.chunksize'] "
                            f"(currently {nmax}) {inc_threshold}"
                        )
                    else:
                        msg = (
                            "Exceeded cell block limit in Agg.  Please set "
                            "the value of rcParams['agg.path.chunksize'], "
                            f"(currently {nmax}) to be greater than 100 "
                            + inc_threshold
                        )

                raise OverflowError(msg) from None

    def draw_mathtext(self, gc, x, y, s, prop, angle):
        """Draw mathtext using :mod:`matplotlib.mathtext`."""
        # y is downwards.
        parse = self.mathtext_parser.parse(
            s, self.dpi, prop, antialiased=gc.get_antialiased())
        c = cos(radians(angle))
        s = sin(radians(angle))
        for font, size, char, dx, dy in parse.glyphs:  # dy is upwards.
            font.set_size(size, self.dpi)
            bitmap = font._render_glyph(
                font.get_char_index(char),
                # The "y" parameter is upwards (per FreeType).
                x + dx * c - dy * s, self.height - y + dx * s + dy * c, angle,
                get_hinting_flag())
            # draw_text_image's y is downwards & the bitmap bottom side.
            self._renderer.draw_text_image(
                bitmap["buffer"],
                bitmap["left"],
                int(self.height) - bitmap["top"] + bitmap["buffer"].shape[0],
                0, gc)
        if not angle:
            for dx, dy, w, h in parse.rects:  # dy is upwards & the rect top side.
                self._renderer.draw_text_image(
                    np.full((round(h), round(w)), np.uint8(0xff)),
                    round(x + dx), round(y - dy - h),
                    0, gc)
        else:
            rgba = gc.get_rgb()
            if len(rgba) == 3 or gc.get_forced_alpha():
                rgba = rgba[:3] + (gc.get_alpha(),)
            gc1 = self.new_gc()
            gc1.set_linewidth(0)

Review comment (suggestion):
There's already an `s` as input to the function, so this could be a bit confusing (also type checking probably wouldn't like it.)

Code after:
                        f"= {path.simplify_threshold} "
                        "on the input)."
                        )
                    if nmax > 100:
                        msg = (
                            "Exceeded cell block limit in Agg.  Please reduce "
                            "the value of rcParams['agg.path.chunksize'] "
                            f"(currently {nmax}) {inc_threshold}"
                        )
                    else:
                        msg = (
                            "Exceeded cell block limit in Agg.  Please set "
                            "the value of rcParams['agg.path.chunksize'], "
                            f"(currently {nmax}) to be greater than 100 "
                            + inc_threshold
                        )

                raise OverflowError(msg) from None

    def draw_mathtext(self, gc, x, y, s, prop, angle):
        """Draw mathtext using :mod:`matplotlib.mathtext`."""
        # y is downwards.
        parse = self.mathtext_parser.parse(
            s, self.dpi, prop, antialiased=gc.get_antialiased())
        cos = math.cos(math.radians(angle))
        sin = math.sin(math.radians(angle))
        for font, size, _char, glyph_index, dx, dy in parse.glyphs:  # dy is upwards.
            font.set_size(size, self.dpi)
            hf = font._hinting_factor
            font._set_transform(
                [[round(0x10000 * cos / hf), round(0x10000 * -sin)],
                 [round(0x10000 * sin / hf), round(0x10000 * cos)]],
                [round(0x40 * (x + dx * cos - dy * sin)),
                 # FreeType's y is upwards.
                 round(0x40 * (self.height - y + dx * sin + dy * cos))]
            )
            bitmap = font._render_glyph(
                glyph_index, get_hinting_flag(),
                RenderMode.NORMAL if gc.get_antialiased() else RenderMode.MONO)
            buffer = np.asarray(bitmap.buffer)
            if not gc.get_antialiased():
                buffer *= 0xff
            # draw_text_image's y is downwards & the bitmap bottom side.
            self._renderer.draw_text_image(
                buffer,
                bitmap.left, int(self.height) - bitmap.top + buffer.shape[0],
                0, gc)
        rgba = gc.get_rgb()
        if len(rgba) == 3 or gc.get_forced_alpha():
            rgba = rgba[:3] + (gc.get_alpha(),)
        gc1 = self.new_gc()