控制默认字体的设置

根据官方文档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默认字体 内容请搜索云海天教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持云海天教程!

matplotlib的默认字体_浅谈matplotlib默认字体设置探索相关推荐

  1. mysql signed 长度_浅谈mysql字段长度设置

    mysql 中最常用的数据类型是tinyint,smallint,int,bigint,char,varchar; char(n)和varchar(n)存储固定长度的字符数据,长度最大为254字节.使 ...

  2. python axes_浅谈matplotlib.pyplot与axes的关系

    最近在学习数据可视化,梳理一下其中一些诸如pandas绘图.matplotlib绘图.pyplot(plt).axes等概念. 重要的事情说三遍:axes不是axis!axes不是axis!axes不 ...

  3. 【转】图标字体化浅谈

    在做手机端Web App项目中,经常会遇到小图标在手机上显示比较模糊的问题,经过实践发现了一种比较好的解决方案,图标字体化.在微社区项目中,有很多小的Icon(图标),如分享.回复.赞.返回.话题.访 ...

  4. 《计算机辅助教学及应用实践研究》,《论文_浅谈计算机辅助教学(定稿)》

    <论文_浅谈计算机辅助教学(定稿)> (3页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 9.9 积分 摘要:计算机辅助教学中要用到多媒体课件 ...

  5. python判断两个对象是否为相等使用的运算符是_Python入门_浅谈逻辑判断与运算符...

    这是关于Python的第6篇文章,主要介绍下逻辑判断与运算符. (一) 逻辑判断: 如果要实现一个复杂的功能程序,逻辑判断必不可少.逻辑判断的最基本标准:布尔类型. 布尔类型只有两个值:True和Fa ...

  6. js拆字_分图程序 _制作个人字体_手写字制作ttf字体方法

    js拆字_分图程序 _制作个人字体_手写字制作ttf字体方法 前言 FontForgeBuilds制作ttf FontForgeBuilds制作个人字体 Adobe_Fireworks_CS5批量转换 ...

  7. pc端rem适配_浅谈pc端rem字体设置的问题

    1.内容在一屏内显示的,采用了(内容框)上下左右居中的办法,里面的内容绝对于这个内容框定位.这样一来,在不同大小屏中,内容总是在中间,看起来较正常 2.长,宽,LEFT,TOP,RIGHT,BOTTO ...

  8. python中 是什么类型_浅谈python中的变量默认是什么类型

    浅谈python中的变量默认是什么类型 1.type(变量名),输出的结果就是变量的类型: 例如 >>> type(6) 2.在Python里面变量在声明时,不需要指定变量的类型,变 ...

  9. python读取图像数据流_浅谈TensorFlow中读取图像数据的三种方式

    本文面对三种常常遇到的情况,总结三种读取数据的方式,分别用于处理单张图片.大量图片,和TFRecorder读取方式.并且还补充了功能相近的tf函数. 1.处理单张图片 我们训练完模型之后,常常要用图片 ...

最新文章

  1. mysql 书签查找_my-bookmark
  2. spring junit 测试
  3. Rhel5.6下构建在线邮件服务系统并实现不同网段不同域名间的邮件互发
  4. boost::detail::allocator模块的测试程序
  5. leetcode881. 救生艇(贪心算法加双指针)
  6. P2657 [SCOI2009]windy数
  7. Android 系统(86)---mtk平台上如何开启f2fs
  8. poto——剧院魅影——phantom of the opera
  9. 吴恩达机器学习学习笔记第六章:机器学习中的线性代数操作python3版(含numpy、panda库的使用)
  10. 状态机(FSM)的介绍--以检测序列1001为例
  11. Java帧率,android应用性能优化之帧率 - hellominefriend的个人空间 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...
  12. python多维数组添加元素_numpy中三维数组中加入元素后的位置详解
  13. 赛尔笔记 | 自然语言处理中的迁移学习(下)
  14. ACCESS 中屏蔽shift键
  15. 利用IPv6的地址特性写一个攻击甩锅程序
  16. HIVE性能调优总结
  17. #python 自动识别视频字幕
  18. die_visual
  19. 使用Python为人脸自动生成口罩
  20. 马斯洛需求层次与产品的关系

热门文章

  1. 创新设计模式:抽象工厂模式
  2. 使用Dropwizard度量标准监视和测量无功应用
  3. Neo4j:使用LOAD CSV检测CSV标头中的恶意空间
  4. JavaOne 2016后续活动
  5. 功能与命令式编程。 Java 8中的斐波那契,素数和阶乘
  6. eclipse鼠标变十了_Eclipse在过去十年中的主要成就
  7. 存根类 测试代码 java_为旧版代码创建存根-测试技术6
  8. 在Spring JDBC中添加C3PO连接池
  9. Spring Integration 4.0:完整的无XML示例
  10. Java开发人员的5种工具