Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@mpflanzer

Description

@mpflanzer
Issue body actions

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

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 (

if self.get_path_effects():
) 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.