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 would not try to apply all the font in font list to draw all characters in the given string. #18883

Closed
Labels
Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: text/fonts
Milestone
@Hsins

Description

@Hsins

Bug report

Bug summary

The document pageConfiguring the font family said that:

You can explicitly set which font family is picked up for a given font style (e.g., 'serif', 'sans-serif', or 'monospace').
In the example below, we only allow one font family (Tahoma) for the sans-serif font style. You the default family with the font.family rc param, e.g.,:

rcParams['font.family']='sans-serif'

and for the font.family you set a list of font styles to try to find in order:

rcParams['font.sans-serif']= ['Tahoma','DejaVu Sans','Lucida Grande','Verdana']

But the mechanism behind the strings rendering with the font-family is not as same as what most users think.

  • Thematplotlib just finds the font in the font list and apply the first valid one (can be found in the given path) to all characters in the given string.
  • We can use a list of fonts to the font-family settings in Visual Studio Code, Sublime Text, and websites. They have their own algorithm to deal with the problem of fonts fallback so that we can apply each font in the list in order to draw the correct character. Refer toHow do web browsers implement font fallback?

Wouldmatplotlib have any plan to implement this feature? There were so many users got into the trouble of missing fonts when we want to show the string mixed with CJK characters and Latin characters.

Code for reproduction

Just take a look at thisColab Notebook.

use['DejaVu Sans', 'SimHei', 'sans-serif']

# Setup the fontsmatplotlib.rcParams['font.sans-serif']= ['DejaVu Sans','SimHei','sans-serif']defmodel(x,p):returnx** (2*p+1)/ (1+x** (2*p))x=np.linspace(0.75,1.25,201)fig,ax=plt.subplots()forpin [10,15,20,30,50,100]:ax.plot(x,model(x,p),label=p)ax.legend(title='Order')ax.set(xlabel='電壓 Voltage (mV)')ax.set(ylabel='電流 Current (A)')ax.autoscale(tight=True)
  • 電壓 and電流 can't be correctly rendered with the current fontDejaVu Sans.

use['SimHei', 'DejaVu Sans', 'sans-serif']

# Setup the fontsmatplotlib.rcParams['font.sans-serif']= ['SimHei','DejaVu Sans','sans-serif']defmodel(x,p):returnx** (2*p+1)/ (1+x** (2*p))x=np.linspace(0.75,1.25,201)fig,ax=plt.subplots()forpin [10,15,20,30,50,100]:ax.plot(x,model(x,p),label=p)ax.legend(title='Order')ax.set(xlabel='電壓 Voltage (mV)')ax.set(ylabel='電流 Current (A)')ax.autoscale(tight=True)
  • 電壓 and電流 can be correctly rendered with the current fontSimHei.
  • Voltage andCurrent are also be rendered with the current fontSimHei.

Expected outcome

We would like to apply the Chinese fontSimHei to the Chinese characters and the English fontDejaVu Sans to the English characters. Just like what we usefont-family style in CSS:

Similar Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: text/fonts

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp