Skip to content

Fontweight of color labels prevents saving as SVG #39

@afrendeiro

Description

@afrendeiro

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions