FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[Doc]: add how to know available fonts... · Issue #21761 · matplotlib/matplotlib · GitHub

Repository navigation

[Doc]: add how to know available fonts... #21761

Closed

Description

Documentation Link

https://matplotlib.org/stable/tutorials/text/text_props.html#default-font

Problem

In https://matplotlib.org/stable/tutorials/text/text_props.html#default-font we are told that we can use any "available fonts" for fontfamily. It would be nice if this tutorial, or another, indicated how to get that list of available fonts, and then specfically how to specify them in fontfamily. I tried a couple of things on stack overflow, but font family does not appear to accept full strings like "Times New Roman", so I assume I need to specify something more low level?

Overall I find font handling still quite confusing, and it seems it requires deeper knwoledge than most users are going to have (or its explained somewhere that is not adequately cross linked).

Suggested improvement

No response

Matplotlib Version

main

Activity

  1. jklymak commented on Nov 26, 2021

    MemberAuthor

    I'll ping @aitikgupta here because I think he knows the font handling pretty well, and maybe could suggest an in-Matplotlib way of getting the right info (obviously we can't specify for all OS-es where the fonts are stored).

  2. tfpf commented on Nov 26, 2021

    Contributor

    font family does not appear to accept full strings like "Times New Roman"

    For me, on WSL, the RC parameter font.family accepts 'Times New Roman', or the name of any installed font, in a case-insensitive manner.

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    mpl.rcParams['font.family'] = 'mV bOlI'
    plt.figure().text(0.1, 0.5, 'This is MV Boli', size=35)
    plt.show()
    

    import matplotlib as mpl
    import matplotlib.pyplot as plt
    mpl.rcParams['font.family'] = 'tImeS nEw ROmaN'
    plt.figure().text(0.1, 0.5, 'This is Times New Roman', size=35)
    plt.show()
    

    Maybe 'available font' means 'installed font'?

  3. jklymak commented on Nov 26, 2021

    MemberAuthor

    Ah, OK, fair enough. Still the main point is that the list of possible fonts is not readily accessible.

  4. anntzer commented on Nov 26, 2021

    Contributor

    The available names are the .name attributes of the entries in matplotlib.font_manager.fontManager.ttflist. Agreed this could be 1) better documented and 2) more easily accessible.

  5. jklymak commented on Nov 26, 2021

    MemberAuthor

    Perfect, thanks! I actually think a little wrapper around that would help people (me). Even just matplotlib.show_available_fontnames (if the top level is where we keep this sort of thing). I'll mark as a good first issue because I think this would be relatively straightforward to add and document.

  6. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Nov 26, 2021
  7. ojeda-e commented on Nov 26, 2021

    Can I work on this as a good first issue over the weekend? :)

    The suggestion by @jklymak at the top level makes sense. Maybe another option to consider is matplotlib.font_manager.font_names?

    Thanks

  8. tacaswell commented on Nov 26, 2021

    Member

    @ojeda-e Please have at it!

    If you think there are a couple of reasonable ways to implement this, it would make it much easier to review if you include a discussion of why you picked the implementation you did in the comments on the PR.

  9. ojeda-e commented on Nov 26, 2021

    Thanks @tacaswell!
    Sounds good, I'll make sure a clear discussion is added.

  10. jklymak commented on Nov 26, 2021

    MemberAuthor

    I also don't know that it is a problem to have a low-level access and an upper-level access that wraps it. There are a few things that are nice to have near top level so folks don't have to try to remember the name of the library where they are implemented (the balance being everything can't be top level!)

  11. aitikgupta commented on Nov 27, 2021

    Contributor

    Maybe 'available font' means 'installed font'?

    Even after installing a font it doesn't end up in Matplotlib's font cache and in turn, isn't available; one would need to rebuild it.
    (note: rebuild_if_missing is supposed to rebuild it if a font family isn't found)

    There existed a way earlier (it wasn't a public function, but the top results of "matplotlib rebuild font cache" on Google still show this old website and SOs whose old answers mention _rebuild())

    I generally do this another way programmatically:

    from pathlib import Path
    import matplotlib as mpl
    import matplotlib.font_manager as fm
    
    fm_path = Path(mpl.get_cachedir(), f"fontlist-v{fm.FontManager.__version__}.json")
    fm = fm.FontManager()
    fm.json_dump(fm, fm_path)
  12. jklymak commented on Nov 28, 2021

    MemberAuthor

    So how do you "install" an "available" font?

  13. aitikgupta commented on Nov 28, 2021

    Contributor

    So how do you "install" an "available" font?

    We "install" a font natively (a double click on a TTF/OTF file will bring up the installation) - the utility is provided by the OS, and the font is installed globally in the system.

    And once it is "installed", it can be made "available" for Matplotlib after rebuilding font cache.

  14. jklymak commented on Nov 28, 2021

    MemberAuthor

    OK, so you are saying that just because the user does a system install of a font doesn't necessarily mean Matplotlib will consider it available, because it has to rebuild the cache first.

  15. aitikgupta commented on Nov 28, 2021

    Contributor

    OK, so you are saying that just because the user does a system install of a font doesn't necessarily mean Matplotlib will consider it available, because it has to rebuild the cache first.

    yep!

  16. added this to the v3.6.0 milestone on Dec 7, 2021
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

    Documentation🌱 Good first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL