婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 淺談matplotlib默認字體設置探索

淺談matplotlib默認字體設置探索

熱門標簽:地圖標注可以遠程操作嗎 如何申請400電話代理 智能電話機器人調研 天津塘沽區地圖標注 400電話在線如何申請 滴滴地圖標注公司 杭州房產地圖標注 江門智能電話機器人 甘肅高頻外呼系統

控制默認字體的設置

根據官方文檔https://matplotlib.org/tutorials/text/text_props.html#default-font可知:

The base default font is controlled by a set of rcParams

默認字體是由一組rcParams控制的。

rcParam usage
‘font.family' List of either names of font or {‘cursive', ‘fantasy', ‘monospace', ‘sans', ‘sans serif', ‘sans-serif', ‘serif'}
‘font.style' The default style, ex ‘normal', ‘italic'
‘font.variant' Default variant, ex ‘normal', ‘small-caps' (untested)
‘font.stretch' Default stretch, ex ‘normal', ‘condensed' (incomplete)
‘font.weight' Default weight. Either string or integer
‘font.size' Default font size in points. Relative font sizes (‘large', ‘x-small') are computed against this size

我們最關心的當然是'font.family','font.family'的取值有三種:

  • 單一字體名稱。
  • 字體名稱列表。
  • {'cursive', 'fantasy', 'monospace', 'sans', 'sans serif', 'sans-serif', 'serif'}中的某一個值。

對于字體名稱,可以通過ttflist獲取。

from matplotlib.font_manager import fontManager 
fontManager.ttflist

對于{'cursive', 'fantasy', 'monospace', 'sans', 'sans serif', 'sans-serif', 'serif'} ,它與實際字體名稱之間的映射關系由以下rcParams控制:

family alias rcParam with mappings
‘serif' ‘font.serif'
‘monospace' ‘font.monospace'
‘fantasy' ‘font.fantasy'
‘cursive' ‘font.cursive'
{‘sans', ‘sans serif', ‘sans-serif'} ‘font.sans-serif'

'font.sans-serif'等取值其實都代表一個字體列表。

如何設置默認字體

官方文檔給出了設置默認字體的方法建議:

To set the default font to be one that supports the code points you need, prepend the font name to ‘font.family' or the desired alias lists
matplotlib.rcParams[‘font.sans-serif'] = [‘Source Han Sans TW', ‘sans-serif']
or set it in your .matplotlibrc file:
font.sans-serif: Source Han Sans TW, Arial, sans-serif
To control the font used on per-artist basis use the ‘name', ‘fontname' or ‘fontproperties' kwargs documented above.

  • 通過常見的方法設置: matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif']
  • 設置.matplotlibrc文件

.matplotlibrc文件中的字體設置

配置文件中重要的就是'font.sans-serif'等字體家族列表,列表是有優先級的,越靠前字體的優先級越高,所有很多教程中都要求把需要設置的字體設置為列表的第一個元素。

## ***************************************************************************
## * FONT                                  *
## ***************************************************************************
## The font properties used by `text.Text`.
## See https://matplotlib.org/api/font_manager_api.html for more information
## on font properties. The 6 font properties used for font matching are
## given below with their default values.
##
## The font.family property has five values:
##   - 'serif' (e.g., Times),
##   - 'sans-serif' (e.g., Helvetica),
##   - 'cursive' (e.g., Zapf-Chancery),
##   - 'fantasy' (e.g., Western), and
##   - 'monospace' (e.g., Courier).
## Each of these font families has a default list of font names in decreasing
## order of priority associated with them. When text.usetex is False,
## font.family may also be one or more concrete font names.
##
## The font.style property has three values: normal (or roman), italic
## or oblique. The oblique style will be used for italic, if it is not
## present.
##
## The font.variant property has two values: normal or small-caps. For
## TrueType fonts, which are scalable fonts, small-caps is equivalent
## to using a font size of 'smaller', or about 83%% of the current font
## size.
##
## The font.weight property has effectively 13 values: normal, bold,
## bolder, lighter, 100, 200, 300, ..., 900. Normal is the same as
## 400, and bold is 700. bolder and lighter are relative values with
## respect to the current weight.
##
## The font.stretch property has 11 values: ultra-condensed,
## extra-condensed, condensed, semi-condensed, normal, semi-expanded,
## expanded, extra-expanded, ultra-expanded, wider, and narrower. This
## property is not currently implemented.
##
## The font.size property is the default font size for text, given in pts.
## 10 pt is the standard value.
##
## Note that font.size controls default text sizes. To configure
## special text sizes tick labels, axes, labels, title, etc, see the rc
## settings for axes and ticks. Special text sizes can be defined
## relative to font.size, using the following values: xx-small, x-small,
## small, medium, large, x-large, xx-large, larger, or smaller

#font.family: sans-serif
#font.style:  normal
#font.variant: normal
#font.weight: normal
#font.stretch: normal
#font.size:  10.0

#font.serif:   DejaVu Serif, Bitstream Vera Serif, Computer Modern Roman, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
#font.sans-serif: DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
#font.cursive:  Apple Chancery, Textile, Zapf Chancery, Sand, Script MT, Felipa, cursive
#font.fantasy:  Comic Neue, Comic Sans MS, Chicago, Charcoal, ImpactWestern, Humor Sans, xkcd, fantasy
#font.monospace: DejaVu Sans Mono, Bitstream Vera Sans Mono, Computer Modern Typewriter, Andale Mono, Nimbus Mono L, Courier New, Courier, Fixed, Terminal, monospace

通過rc函數設置默認字體屬性的方法

根據文檔可知
傳統的字體設置方法plt.rcParams['font.sans-serif'] = ['simhei']等價于

font = {'sans-serif' : ['simhei']}
plt.rc('font', **font) 
matplotlib.pyplot.rc(group, **kwargs)
Set the current rcParams. group is the grouping for the rc, e.g., for lines.linewidth the group is lines, for axes.facecolor, the group is axes, and so on. Group may also be a list or tuple of group names, e.g., (xtick, ytick). kwargs is a dictionary attribute name/value pairs, e.g.,:
rc('lines', linewidth=2, color='r')
sets the current rcParams and is equivalent to:
rcParams['lines.linewidth'] = 2
rcParams['lines.color'] = 'r'

到此這篇關于淺談matplotlib默認字體設置探索的文章就介紹到這了,更多相關matplotlib默認字體 內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Python matplotlib修改默認字體的操作

標簽:重慶 長春 東莞 河池 臨汾 德宏 漢中 廊坊

巨人網絡通訊聲明:本文標題《淺談matplotlib默認字體設置探索》,本文關鍵詞  淺談,matplotlib,默認,字體,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《淺談matplotlib默認字體設置探索》相關的同類信息!
  • 本頁收集關于淺談matplotlib默認字體設置探索的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 栖霞市| 咸宁市| 正定县| 唐山市| 阳原县| 乐安县| 昌宁县| 元阳县| 绥德县| 门头沟区| 永兴县| 泸溪县| 云南省| 奇台县| 绩溪县| 光山县| 大兴区| 许昌县| 肇州县| 马鞍山市| 周口市| 来凤县| 定南县| 洛阳市| 洪湖市| 简阳市| 东安县| 铜鼓县| 长沙县| 绥滨县| 饶阳县| 托克托县| 本溪市| 田东县| 泾川县| 塔城市| 海盐县| 延长县| 乳山市| 荣成市| 武冈市|