Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fontweight of color labels prevents saving as SVG #39

Open
afrendeiro opened this issue Jul 24, 2024 · 2 comments
Open

Fontweight of color labels prevents saving as SVG #39

afrendeiro opened this issue Jul 24, 2024 · 2 comments

Comments

@afrendeiro
Copy link
Collaborator

When passing label to mp.ColorMesh or mp.Colors and saving as SVG I get an error:

...

File ~/.local/lib/python3.11/site-packages/matplotlib/text.py:797, in Text.draw(self, renderer)
    793             textrenderer.draw_tex(gc, x, y, clean_line,
    794                                   self._fontproperties, angle,
    795                                   mtext=mtext)
    796         else:
--> 797             textrenderer.draw_text(gc, x, y, clean_line,
    798                                    self._fontproperties, angle,
    799                                    ismath=ismath, mtext=mtext)
    801 gc.restore()
    802 renderer.close_group('text')

File ~/.local/lib/python3.11/site-packages/matplotlib/backends/backend_svg.py:1269, in RendererSVG.draw_text(self, gc, x, y, s, prop, angle, ismath, mtext)
   1267     self._draw_text_as_path(gc, x, y, s, prop, angle, ismath, mtext)
   1268 else:
-> 1269     self._draw_text_as_text(gc, x, y, s, prop, angle, ismath, mtext)
   1271 if gc.get_url() is not None:
   1272     self.writer.end('a')

File ~/.local/lib/python3.11/site-packages/matplotlib/backends/backend_svg.py:1112, in RendererSVG._draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext)
   1110 if prop.get_variant() != 'normal':
   1111     font_parts.append(prop.get_variant())
-> 1112 weight = fm.weight_dict[prop.get_weight()]
   1113 if weight != 400:
   1114     font_parts.append(f'{weight}')

KeyError: 600

I think this is because maybe a default is making this label bold (600)?
Also tried setting label_props=dict(fontweight=400) or label_props=dict(fontweight='regular') with same effect.
Saving as PDF works, but can't be opened by Inkscape for example.
Might be only Linux-specific.

@Mr-Milk
Copy link
Member

Mr-Milk commented Jul 24, 2024

Yes, by default the legendkit will try to use the bold setting for the title in the legend, the exact weight value is decided by matplotlib. May I ask which font are you using?

@afrendeiro
Copy link
Collaborator Author

Arial. These are the settings I use often:

import matplotlib.pyplot as plt
plt.rcParams["svg.fonttype"] = "none"
plt.rcParams["font.family"] = "Arial"
plt.rcParams["font.sans-serif"] = ["Arial"]
plt.rcParams["text.usetex"] = False

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants