最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談matplotlib默認(rèn)字體設(shè)置探索

 更新時(shí)間:2021年02月03日 08:44:11   作者:mighty13  
這篇文章主要介紹了matplotlib默認(rèn)字體設(shè)置探索,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

控制默認(rèn)字體的設(shè)置

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

The base default font is controlled by a set of rcParams

默認(rèn)字體是由一組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

我們最關(guān)心的當(dāng)然是'font.family','font.family'的取值有三種:

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

對(duì)于字體名稱,可以通過ttflist獲取。

from matplotlib.font_manager import fontManager 
fontManager.ttflist

對(duì)于{'cursive', 'fantasy', 'monospace', 'sans', 'sans serif', 'sans-serif', 'serif'} ,它與實(shí)際字體名稱之間的映射關(guān)系由以下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'等取值其實(shí)都代表一個(gè)字體列表。

如何設(shè)置默認(rèn)字體

官方文檔給出了設(shè)置默認(rèn)字體的方法建議:

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.

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

.matplotlibrc文件中的字體設(shè)置

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

## ***************************************************************************
## * 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函數(shù)設(shè)置默認(rèn)字體屬性的方法

根據(jù)文檔可知
傳統(tǒng)的字體設(shè)置方法plt.rcParams['font.sans-serif'] = ['simhei']等價(jià)于

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'

到此這篇關(guān)于淺談matplotlib默認(rèn)字體設(shè)置探索的文章就介紹到這了,更多相關(guān)matplotlib默認(rèn)字體 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python selenium的安裝和下載谷歌瀏覽器鏡像驅(qū)動(dòng)

    Python selenium的安裝和下載谷歌瀏覽器鏡像驅(qū)動(dòng)

    Selenium是一個(gè)用于web自動(dòng)化測(cè)試的框架,在使用Ajax請(qǐng)求數(shù)據(jù)的頁面中,會(huì)出現(xiàn) sign ,token等密鑰,借助使用Selenium框架來實(shí)現(xiàn)數(shù)據(jù)爬取很不錯(cuò),本文給大家介紹Python selenium的安裝和下載谷歌瀏覽器鏡像驅(qū)動(dòng),需要的朋友可以參考下
    2022-11-11
  • python必備庫Matplotlib畫圖神器

    python必備庫Matplotlib畫圖神器

    這篇文章主要介紹了python必備庫Matplotlib畫圖神器,Matplotlib 是 Python 中最受歡迎的數(shù)據(jù)可視化軟件包之一,支持跨平臺(tái)運(yùn)行,它是 Python 常用的 2D 繪圖庫,同時(shí)它也提供了一部分 3D 繪圖接口,更多詳細(xì)內(nèi)容,需要的小伙伴可以參考一下下面文章具體內(nèi)容
    2022-03-03
  • Python中Scrapy爬蟲圖片處理詳解

    Python中Scrapy爬蟲圖片處理詳解

    這篇文章主要介紹了Python中Scrapy爬蟲圖片處理方式和原理,需要的朋友學(xué)習(xí)參考下吧。
    2017-11-11
  • Python 讀取WAV音頻文件 畫頻譜的實(shí)例

    Python 讀取WAV音頻文件 畫頻譜的實(shí)例

    這篇文章主要介紹了Python 讀取WAV音頻文件 畫頻譜的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • python通過配置文件共享全局變量的實(shí)例

    python通過配置文件共享全局變量的實(shí)例

    今天小編就為大家分享一篇python通過配置文件共享全局變量的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • PyCharm2020.1.1與Python3.7.7的安裝教程圖文詳解

    PyCharm2020.1.1與Python3.7.7的安裝教程圖文詳解

    這篇文章主要介紹了PyCharm2020.1.1與Python3.7.7的安裝教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • 在PyCharm中遇到pip安裝 失敗問題及解決方案(pip失效時(shí)的解決方案)

    在PyCharm中遇到pip安裝 失敗問題及解決方案(pip失效時(shí)的解決方案)

    這篇文章主要介紹了在PyCharm中遇到pip安裝失敗問題及解決方案(pip失效時(shí)的解決方案),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • Python有關(guān)Unicode UTF-8 GBK編碼問題詳解

    Python有關(guān)Unicode UTF-8 GBK編碼問題詳解

    本文主要介紹了Python有關(guān)Unicode UTF-8 GBK編碼問題詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • python 實(shí)現(xiàn)繪制整齊的表格

    python 實(shí)現(xiàn)繪制整齊的表格

    今天小編就為大家分享一篇python 實(shí)現(xiàn)繪制整齊的表格,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • 解析PyCharm Python運(yùn)行權(quán)限問題

    解析PyCharm Python運(yùn)行權(quán)限問題

    這篇文章主要介紹了PyCharm Python運(yùn)行權(quán)限問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-01-01

最新評(píng)論

富平县| 五峰| 酉阳| 灵武市| 邳州市| 邳州市| 宝清县| 呈贡县| 正安县| 建德市| 筠连县| 南汇区| 湘潭县| 外汇| 桓仁| 唐河县| 剑阁县| 广东省| 宣威市| 洪洞县| 浦东新区| 楚雄市| 富阳市| 平武县| 仁寿县| 禄丰县| 博罗县| 顺昌县| 泗阳县| 呼玛县| 玉山县| 修武县| 万载县| 滨海县| 丰台区| 遵化市| 鄢陵县| 桃园市| 加查县| 潮州市| 高雄县|