matplotlib使用(20201224)

matplotlib各种样例

https://matplotlib.org/gallery/lines_bars_and_markers/categorical_variables.html#sphx-glr-gallery-lines-bars-and-markers-categorical-variables-py

用啥样子的图直接去找就完了

关于图中不显示汉字的问题

解答:

https://zhuanlan.zhihu.com/p/104081310

简要说明

在前面加入两行代码

import matplotlib
matplotlib.rc('font', family='AR PL UKai CN')

 

通过源码可以发现是matplotlib中内置方法matplotlib.rc中可以接收字体

matplotlib.rc("font",family='MicroSoft YaHei',weight="bold")

 MicroSoft为字体微软雅黑,如果报错,则说明库中没有这个字体,可以自己查看具体的字体。

查看系统所有字体的代码

# 查询当前系统所有字体
from matplotlib.font_manager import FontManager
import subprocess

mpl_fonts = set(f.name for f in FontManager().ttflist)

print('all font list get from matplotlib.font_manager:')
for f in sorted(mpl_fonts):
    print('\t' + f)

找到其中的中文字体(CN )然后填入即可。

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值