#26704·matplotlib

[Bug]: svg.fonttype = 'none' is ignored if patheffects are set

Author: mpflanzerCreated Sep 6, 2023Updated Sep 29, 2026
Labelsbackend: svgtopic: text/fonts

Bug summary

This might not be a bug per se but I think a different behaviour would make more sense. Currently the svg.fonttype parameter of the SVG backend is ignored if any path effect is set. Though I would argue that it might still desirable to apply path effects to the axis etc and then choose a font which is matching those effects instead of rendering the text with exactly the same effects.

In my case I noticed it with the "xckd" style plotting which also selects a matching font. But due to the path effects taking precedence the SVG would never use the font making it impossible to find (search) text in the SVG when displayed on a website.

Code for reproduction

python
import matplotlib
import matplotlib.pyplot as plt

with plt.xkcd():
    plt.rcParams['svg.fonttype'] = 'none'

    fig = plt.figure()
    fig, ax = plt.subplots()
    ax.annotate("Test", (0.5, 0.5))
    plt.savefig("test.svg")

Actual outcome

Instead of a text tag in the SVG the text is rendered as path

Expected outcome

The text represented by a text tag in the SVG.

Additional information

The "problem" originates in text.py line 785 (https://github.com/matplotlib/matplotlib/blob/781c6a0e8ac9a42f4079918b91d4310675dc1549/lib/matplotlib/text.py#L785) where the SVG renderer is swapped against the path effects renderer.

The behaviour I would prefer could be achieved with the following patch but it feels rather hacky. Any suggestion how to achieve this in a better way would be welcome.

diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py
index 7a58ce7172..8197910820 100644
--- a/lib/matplotlib/text.py
+++ b/lib/matplotlib/text.py
@@ -782,7 +782,9 @@ class Text(Artist):
                     y = canvash - y
                 clean_line, ismath = self._preprocess_math(line)
 
-                if self.get_path_effects():
+                from matplotlib.backends.backend_svg import RendererSVG
+
+                if not (isinstance(renderer._renderer, RendererSVG) and mpl.rcParams['svg.fonttype'] == "none") and self.get_path_effects():
                     from matplotlib.patheffects import PathEffectRenderer
                     textrenderer = PathEffectRenderer(
                         self.get_path_effects(), renderer)

Operating system

No response

Matplotlib Version

3.7.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

pip