控制默认字体的设置
根据官方文档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'
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]