Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Matplotlib chooses the wrong font for unrecognized weights #8550

Closed
@Rufflewind

Description

@Rufflewind

Bug report

Bug summary

With a lot of the modern fonts containing exotic font weights like “Thin” or “Ultra bold”, matplotlib will sometimes pick the wrong font weight because it assumes that any font weight that it doesn’t recognize is either normal (400) or bold (700), even though there is a “Regular” available. Ultimately which one matplotlib picksseems to be actually kind of random, probably depending on the order in which the fonts appear in the font cache.

This is what thelogic infont_manager.py looks like:

weight=next((wforwinweight_dictifsfnt4.find(w)>=0),None)ifnotweight:iffont.style_flags&ft2font.BOLD:weight=700else:weight=400

sfnt4 appears to be a string that contains the full name of the font, including the weight. The problem with this approach is that if it doesn’t recognize the weight, it will simply assume the weight is either 400 or 700.A “Thin” font that was mistakenly labeled 400 might get picked over a “Regular” font.

Here are all theweights currently recognized:

weight_dict= {'ultralight' :100,'light'      :200,'normal'     :400,'regular'    :400,'book'       :400,'medium'     :500,'roman'      :500,'semibold'   :600,'demibold'   :600,'demi'       :600,'bold'       :700,'heavy'      :800,'extra bold' :800,'black'      :900}

I imagine we could add “Thin” and some others into the list, but I don’t think this solves the fundamental problem that fonts with unrecognized weights arepresumed “Regular”/“Bold” and do not have lower precedence than fonts that aredefinitely “Regular”/“Bold”.

TL;DR: It would be nice to have a more robust way to detect font weights and handle unknown font weights.

Matplotlib version

  • Operating System: Arch Linux
  • Matplotlib Version: HEAD
  • Python Version: 3.6.0
  • Jupyter Version (if applicable): n/a
  • Other Libraries: n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp