Python画图设置宋体和新罗马
Times
New Roman
相信很多用
Python进行画图的小伙伴会有困惑,每次画出来的图都是黑体,粘贴到Word里面,和其他的文字也很不搭,但是又懒得改,主要是我一直也没找到很有效的方法,但今天偶然学到一个方法,觉得很有用,就分享给大家
import
matplotlib.pyplot as plt
from
matplotlib import rcParams
config = {
"font.family": 'serif',
python中用matplotlib库画图时,把中文设置为宋体,英文设置为Time New Roman,有时候还需要显示公式。设置方法如下:
import matplotlib.pyplot as plt
from matplotlib import rcParams
import numpy as np
config = {
"font.family":'serif',
"font.size": 18,
"mathtext.fontset":'stix',
"font.s
对于使用 Python 进行图形绘制,你可以使用 Matplotlib 库。你可以通过以下代码设置图中中文字体为仿宋_GB2312,英文字体为 Times New Roman:
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
# 设置仿宋_GB2312字体
zh_font = fm.FontProperties(fname='/path/to/simfang.ttf')
# 设置Times New Roman字体
en_font = fm.FontProperties(fname='/path/to/times.ttf')
# 绘制图形
plt.plot([0, 1, 2, 3], [1, 2, 3, 4])
plt.title("标题", fontproperties=zh_font, fontsize=14)
plt.xlabel("横轴", fontproperties=zh_font, fontsize=12)
plt.ylabel("纵轴", fontproperties=zh_font, fontsize=12)
plt.show()
需要注意的是,请确保你已经安装了仿宋_GB2312和 Times New Roman 字体,并且路径设置正确。
语法错误 SyntaxError: from __future__ imports must occur at the beginning of the file 的分析和解决