Skip to content

TST: Set tests touched by text overhaul to mpl20 style#31300

Draft
QuLogic wants to merge 7 commits intomatplotlib:text-overhaulfrom
QuLogic:text-test-style
Draft

TST: Set tests touched by text overhaul to mpl20 style#31300
QuLogic wants to merge 7 commits intomatplotlib:text-overhaulfrom
QuLogic:text-test-style

Conversation

@QuLogic
Copy link
Member

@QuLogic QuLogic commented Mar 13, 2026

PR summary

This is based on several other PRs to make it easier for me to track what needs changing. I will rebase those extra commits out once ready.

The first commit changes all related tests to mpl20, while the second commit changes a few so that they better work in the new style (e.g., moves a transparent legend over top something so that you can actually confirm that it's transparent.) I do expect to squash these together, but kept them separate so that it'd be easier to review the secondary changes.

AI Disclosure

None

PR checklist

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test forces a low DPI, but I guess this is okay.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably an attempt to save space?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again a low DPI, but probably okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as below, probably to save space? Came in like this from 94d044e

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems like it might be wrong, given the red is a bit different, but it could be an illusion since the border is gone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to set the legend.framealpha rcparam to None to get this test back.

Copy link
Member Author

@QuLogic QuLogic Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new style, ticks on top/right spines are turned off. I'm not sure if we want to re-enable them here, mostly for aesthetic reasons; it's not really relevant to the test per se.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of turning them back on, but no strong feeling either way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bit uncertain why this moved so much; I guess because text is in physical units, while everything else was scaled down for the smaller figure size. I'll try a larger figure to see if it matches again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the figure got smaller in real units, the text stayed the same size in real units, the limits stayed the same in data units, so the text takes up more space in data units.

Either restore the old figure size in inches or make the range of points we try to hit bigger.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, made it bigger and it looks much closer to what it used to be.


@image_comparison(['test_stairs_options.png'], remove_text=True)
@image_comparison(['test_stairs_options.png'], style='mpl20', remove_text=True)
def test_stairs_options():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not yet investigated yet, but this test actually breaks after changing styles:

__________________ test_stairs_options[png] ___________________

args = (), kwds = {'extension': 'png', 'request': <FixtureRequest for <Function test_stairs_options[png]>>}

    @wraps(func)
    def inner(*args, **kwds):
        with self._recreate_cm():
>           return func(*args, **kwds)

/usr/lib64/python3.13/contextlib.py:85: 
 _ _ _ _ _ _ _ _ _ _ _ _
lib/matplotlib/figure.py:3508: in savefig
    self.canvas.print_figure(fname, **kwargs)
lib/matplotlib/backend_bases.py:2275: in print_figure
    result = print_method(
lib/matplotlib/backend_bases.py:2132: in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
lib/matplotlib/backends/backend_agg.py:539: in print_png
    self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
lib/matplotlib/backends/backend_agg.py:487: in _print_pil
    FigureCanvasAgg.draw(self)
lib/matplotlib/backends/backend_agg.py:440: in draw
    self.figure.draw(self.renderer)
lib/matplotlib/artist.py:94: in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
lib/matplotlib/artist.py:71: in draw_wrapper
    return draw(artist, renderer)
lib/matplotlib/figure.py:3275: in draw
    mimage._draw_list_compositing_images(
lib/matplotlib/image.py:133: in _draw_list_compositing_images
    a.draw(renderer)
lib/matplotlib/artist.py:71: in draw_wrapper
    return draw(artist, renderer)
lib/matplotlib/axes/_base.py:3282: in draw
    mimage._draw_list_compositing_images(
lib/matplotlib/image.py:133: in _draw_list_compositing_images
    a.draw(renderer)
lib/matplotlib/artist.py:71: in draw_wrapper
    return draw(artist, renderer)
lib/matplotlib/patches.py:740: in draw
    self._draw_paths_with_artist_properties(
lib/matplotlib/patches.py:723: in _draw_paths_with_artist_properties
    gc.set_dashes(*self._dash_pattern)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <matplotlib.backend_bases.GraphicsContextBase object at 0x7f3016ba3750>, dash_offset = 0.0, dash_list = [0.0, 0.0]

    def set_dashes(self, dash_offset, dash_list):
        """
        Set the dash style for the gc.
    
        Parameters
        ----------
        dash_offset : float
            Distance, in points, into the dash pattern at which to
            start the pattern. It is usually set to 0.
        dash_list : array-like or None
            The on-off sequence as points.  None specifies a solid line. All
            values must otherwise be non-negative (:math:`\\ge 0`).
    
        Notes
        -----
        See p. 666 of the PostScript
        `Language Reference
        <https://www.adobe.com/jp/print/postscript/pdfs/PLRM.pdf>`_
        for more info.
        """
        if dash_list is not None:
            dl = np.asarray(dash_list)
            if np.any(dl < 0.0):
                raise ValueError(
                    "All values in the dash list must be non-negative")
            if dl.size and not np.any(dl > 0.0):
>               raise ValueError(
                    'At least one value in the dash list must be positive')
E               ValueError: At least one value in the dash list must be positive

lib/matplotlib/backend_bases.py:897: ValueError

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #31302 for this issue.

@QuLogic QuLogic force-pushed the text-test-style branch 2 times, most recently from 42792b2 to 8109dbb Compare March 13, 2026 22:48
- `test_backend_ps::test_type3_font` is covered by
  `test_backend_ps::test_multi_font_type3`
- `test_text::test_pdf_chars_beyond_bmp` is covered by
  `test_backend_pdf::test_multi_font_type3` and
  `test_backend_pdf::test_multi_font_type42`
- `test_text::test_pdf_kerning` is covered by
  `test_backend_pdf::test_kerning`
- `test_text::test_pdf_type42_kerning` is covered by
  `test_backend_pdf::test_kerning`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Waiting for other PR

Development

Successfully merging this pull request may close these issues.

2 participants