python matplotlib 解决中文显示乱码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Tourior/article/details/78520757

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

猜你喜欢

转载自blog.csdn.net/Tourior/article/details/78520757
今日推荐