python matplotlib 解决中文显示乱码

python matplotlib 显示中文

matplotlib 中文显示问题

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
# plt.style.use('seaborn-whitegrid') #使用样式
# plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中文
# plt.rcParams['axes.unicode_minus'] = False #显示负号
fig = plt.figure()
ax = plt.axes()
x = np.linspace(0, 10, 1000)
ax.plot(x, np.sin(x));
plt.title('测试图片')
plt.xlabel('横座标名称')
plt.ylabel('纵座标名称')
plt.legend(['图例名称'])
plt.show()

如图中文显示出错
png

增加下列语句

plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中文
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('seaborn-whitegrid') #使用样式
plt.rcParams['font.sans-serif'] = ['SimHei'] #显示中文
plt.rcParams['axes.unicode_minus'] = False #显示负号
fig = plt.figure()
ax = plt.axes()
x = np.linspace(0, 10, 1000)
ax.plot(x, np.sin(x));
plt.title('测试图片')
plt.xlabel('横座标名称')
plt.ylabel('纵座标名称')
plt.legend(['图例名称'])
plt.show()

png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章