Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
This might not be a bug per se but I think a different behaviour would make more sense. Currently thesvg.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
importmatplotlibimportmatplotlib.pyplotaspltwithplt.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 atext
tag in the SVG the text is rendered aspath
Expected outcome
The text represented by atext
tag in the SVG.
Additional information
The "problem" originates intext.py
line 785 (
matplotlib/lib/matplotlib/text.py
Line 785 in781c6a0
ifself.get_path_effects(): |
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.pyindex 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