GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [ENH]: Explicit file paths for font rcParams · Issue #28147 · matplotlib/matplotlib

[ENH]: Explicit file paths for font rcParams #28147

New issue
Copy link
New issue
Copy link
Open
Open
[ENH]: Explicit file paths for font rcParams#28147
Copy link
Labels
New featuretopic: text/fonts

Description

@ChestnutA
ChestnutA
opened on Apr 28, 2024
Issue body actions

Problem

I'm always frustrated while setting the fonts of text in plots. To begin with, I want the readers to be noticed that I do know a couple of ways to set fonts, and I am here just to give an advise.


I use Windows to be the environment here. The phenomenons are as follows.
The font.sans-serif property in file "matplotlibrc" in the "site-packages\matplotlib\mpl-data" directory is "DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif, simkai". As you can see,

  • there is an item called "simkai" in it,
  • and "simkai.ttf" is located in both
    • site-packages\matplotlib\mpl-data\fonts\ttf
    • C:\Windows\fonts

However, Matplotlib is not able to find the font name, and raise the warning "findfont: Generic family 'sans-serif' not found because none of the following families were found: SimKai".

So, where could the user find and set it? There is a json file within the folder %Userprofile%\.matplotlib. The font "simkai.ttf" is named by "kaiti" in json.

On the contrary, after I set plt.rcParams['font.sans-serif']=['SimSun'], the font "simsun" could be recognized correctly. To be noticed, there are no font files named like "simsun*.ttf" in directories mentioned above. There is only a "C:\Windows\fonts\simsun.ttc".

Similar to what occurred with "kaiti", the way and the only way to recognize "simsun" is to search by the json file under %userprofile%.

I consider this searching mode to be wired and inconvenient.

Proposed solution

Maybe, the logic could be removed from the personal configuration on the system disk. Or add the behavior in User Guide?

Activity

  1. ChestnutA
    added
    New feature
    on Apr 28, 2024
  2. anntzer commented on Apr 28, 2024

    @anntzer
    anntzer
    on Apr 28, 2024
    Contributor
    More actions

    I believe this font's name (as indicated in the file metadata) is indeed KaiTi; this is also the name under which the font appears e.g. in Word (I can't actually check this right now. Matplotlib uses that same font name -- the name of the file in the filesystem is immaterial.
    If you know exactly what font file you want to use you can pass it explicitly using https://matplotlib.org/stable/gallery/text_labels_and_annotations/font_file.html, although indeed right now it is not possible (I think) to include a Path() in rcParams["font.sans-serif"] -- perhaps that would be nice to have.

  3. anntzer
    added
    topic: text/fonts
    on Apr 28, 2024
  4. ChestnutA commented on May 2, 2024

    @ChestnutA
    ChestnutA
    on May 2, 2024
    Author
    More actions

    I believe this font's name (as indicated in the file metadata) is indeed KaiTi; this is also the name under which the font appears e.g. in Word (I can't actually check this right now. Matplotlib uses that same font name -- the name of the file in the filesystem is immaterial. If you know exactly what font file you want to use you can pass it explicitly using https://matplotlib.org/stable/gallery/text_labels_and_annotations/font_file.html, although indeed right now it is not possible (I think) to include a Path() in rcParams["font.sans-serif"] -- perhaps that would be nice to have.

    Thank you, I just don't know to do the set the explicit path every time I use matplotlib. While, actually I am using Chinese Operator System. "Kaiti", it is actually called "楷体" in OS.
    So I tried the font names in json file, and they did do correctly in Word. I also has found some uncommon fonts, like "Aptos", "Tinos", which included in Word font selector but couldn't be used in matplotlib.

    There is not an explicit map between Chinese font names and their English versions. So I think this feature needs to be improved better.

  5. anntzer commented on May 5, 2024

    @anntzer
    anntzer
    on May 5, 2024
    Contributor
    More actions

    Ah yes, some fonts are available under multiple names and we currently use only one of them (which may not actually be the OS name). See #4822 (comment).
    Anyways, this issue should be left open at least because allowing explicit paths in the rcParams may be a useful workaround too.

    Reacted by ChestnutA
  6. QuLogic commented on Jun 12, 2026

    @QuLogic
    QuLogic
    on Jun 12, 2026
    Member
    More actions

    Support for using all the font names was added in #31183; using a path in the rcParam is still to be implemented.

  7. QuLogic
    changed the title [-][ENH]: Fonts searching logic[/-] [+][ENH]: Explicit file paths for font rcParams[/+] on Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    New featuretopic: text/fonts

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.