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

Chinese font can`t change the weight · Issue #15529 · matplotlib/matplotlib · GitHub

Repository navigation

Chinese font can`t change the weight #15529

Closed

Description

Bug report

Bug summary
I found that when I use Chinese font, I can`t set the weight. When I change the value of weight, It does not work.

Code for reproduction

When I try this

weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
axis('off')
for i in enumerate(weights):
    num,weight=i
    text(0.5,0.2*num,u'ABC',fontdict={
        'family':'KaiTi',
        'weight':weight,
        'size':30
    })
    text(0,0.2*num,u'哈哈哈',fontdict={
        'family':'KaiTi',
        'weight':weight,
        'size':30
    })
show()

The results show it dose not work.

And when I comment out this line of code

weights = ['light', 'normal', 'medium', 'semibold', 'bold', 'heavy', 'black']
axis('off')
for i in enumerate(weights):
    num,weight=i
    text(0.5,0.2*num,u'ABC',fontdict={
        # 'family':'KaiTi',
        'weight':weight,
        'size':30
    })
    text(0,0.2*num,u'哈哈哈',fontdict={
        # 'family':'KaiTi',
        'weight':weight,
        'size':30
    })
show()

.........:(

I guess maybe it doesn't support Chinese bold. :(

Activity

  1. timhoffm commented on Oct 26, 2019

    Member

    Does it work in other programs? I suppose it's rather a problem with the font and not with matplotlib.

  2. tacaswell commented on Oct 26, 2019

    Member

    When rendering text we pick the font that best matches your fontdict. The way that different weights are encoded is effectively as different fonts (not as some scaling on a single font which is something I learned from @dorafc very recently). In the first case we always pick 'KaiTi' which you only have one variant of installed (or at least not any of the variants you are looking for) so you get both 汉字 and latin characters rendered, but always at the same weight. In the second case you are not selecting a font family so we fall back to the default font (which is likely dejavu sans) which does have multiple weights but does not have the Chinese code pages.

    To get this to work you will need to install a font that both has multiple weights and support Chinese.

    https://matplotlib.org/3.1.1/tutorials/text/text_props.html#text-with-non-latin-glyphs maybe helpful.

    I am going to close this because there is nothing more we can do on the library side. If you have further questions can you please post at https://discourse.matplotlib.org/c/community ?

    Good luck!

  3. anntzer commented on Oct 27, 2019

    Contributor

    Actually I think the error message could be better in this case; we already log a warning when a font of the requested family is not present, we should likewise log when a font of the requested weight (or size, etc.) is not present.

  4. added this to the v3.3.0 milestone on Oct 27, 2019
  5. modified the milestones: v3.3.0, v3.4.0 on Jun 9, 2020
  6. tacaswell commented on Jun 9, 2020

    Member

    Pushing to 3.4 as that is where we re-milestoned the PR to.

  7. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  8. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  9. modified the milestones: v3.6.0, v3.7.0 on Jul 8, 2022
  10. modified the milestones: v3.7.0, v3.7.1 on Feb 14, 2023
  11. modified the milestones: v3.7.1, v3.7.2 on Mar 4, 2023
  12. modified the milestones: v3.7.2, v3.7.3 on Jul 5, 2023
  13. modified the milestones: v3.7.3, v3.8.0 on Sep 9, 2023
  14. removed this from the v3.8.0 milestone on Sep 15, 2023
  15. added this to the v3.11.0 milestone on Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL