@@ -684,6 +684,64 @@ transparency of mapped colors for an Artist.
684684Fonts and Text
685685==============
686686
687+ .. dropdown :: Important
688+ :color: warning
689+ :icon: alert
690+
691+ This release of Matplotlib includes a large update to text processing and rendering.
692+ Within our published wheels, the bundled version of FreeType has been updated, and
693+ the rendering pipeline itself has been overhauled to support modern features and
694+ fonts, as outlined below. It is unfortunately not possible to reproduce the exact
695+ same pixel values for a piece of rendered text as in previous versions.
696+
697+ If you are reliant on pixel-perfect consistency between versions, this will be
698+ broken in this release. For downstream packages that are testing plots, we recommend
699+ a few options:
700+
701+ 1. Update your test images directly; if you are comfortable with requiring 3.11 and
702+ above only, then this is the simplest option. However, it does mean dropping
703+ support for many users with older Matplotlib versions. Alternatively, provide two
704+ sets of test images, one before and one after. This would increase compatibility
705+ at the cost of disk space.
706+ 2. Increase tolerances on tests with text. Note that this might obscure unintended
707+ differences, so be careful with increasing tolerances too high. If you are using
708+ Matplotlib's `.image_comparison ` decorator, you can pass the *tol * argument::
709+
710+ @image_comparison(['plot.png'], tol=5, style='mpl20')
711+ def test_plot():
712+ ...
713+
714+ If you are using `pytest-mpl `_, then you can pass the *tolerance * argument::
715+
716+ @pytest.mark.mpl_image_compare(tolerance=5)
717+ def test_plot():
718+ ...
719+ 3. Remove non-essential text elements. The easiest way to avoid this problem is to
720+ not have any text to worry about. For both the `.image_comparison ` decorator and
721+ `pytest-mpl `_, you can pass the *remove_text * argument::
722+
723+ @image_comparison(['plot.png'], remove_text=True, style='mpl20')
724+ def test_plot():
725+ ...
726+
727+ @pytest.mark.mpl_image_compare(remove_text=True)
728+ def test_plot():
729+ ...
730+
731+ to remove the title and tick texts; note other deliberate texts are not removed.
732+ 4. Replace text with placeholders. If you do need text to exist, but don't intend to
733+ check the exact pixels (for example, to confirm layout is correct), then you can
734+ replace the text with a placeholder of a fixed size. If you are using `pytest `_,
735+ the `.text_placeholders ` fixture may be used to replace text with a fixed-size
736+ box. Consider vendoring a similar fixture in your own tests if necessary.
737+ 5. Use a different image comparison algorithm. While not available in Matplotlib's
738+ testing framework, a `perceptual hashing algorithm `_ may be more appropriate if
739+ you wish to avoid depending on exact pixel values.
740+
741+ .. _perceptual hashing algorithm : https://en.wikipedia.org/wiki/Perceptual_hashing
742+ .. _pytest : http://doc.pytest.org/en/latest/
743+ .. _pytest-mpl : https://pytest-mpl.readthedocs.io/
744+
687745Complex text layout with libraqm
688746--------------------------------
689747
0 commit comments