在pycharm中利用jupyter开发,发现图片不能正常显示中文;
方法一 独立的指定中英文字体
直接指定字体的类型
from matplotlib.font_manager import FontProperties
chinese_font = FontProperties(family='SimHei')
english_font = FontProperties(family='Times New Roman')
然后在标签的位置设定字体,如果不设定,就会用默认的字体,比如
plt.xlabel(‘位置’, fontproperties=chinese_font, fontsize=14)
完整Python代码
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.rcParams.update({
'font.size': 12}) # Setting the global font size to 12
chinese_font = FontProperties(family='SimHei')
english_font = FontProperties(family='Times New Roman')
means = [[1.0, 1.0, 1.0], [0.9, 0.9, 0.9], [0.8, 0.8, 0.8]] # 每个柱子的平均值
stds =