Matplotlib solves the problem of Chinese labels

Solution

# 用于正常显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
# 用来正常显示负号
plt.rcParams['axes.unicode_minus'] = False

sample code

not used

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('ggplot')

if __name__ == '__main__':
    plt.title(u"中文测试")
    plt.xlabel(u'X轴')
    plt.ylabel(u'Y轴')
    plt.plot(np.arange(5), np.arange(5))
    plt.show()

not used

usage

import numpy as np
import matplotlib.pyplot as plt

plt.style.use('ggplot')
# 用于正常显示中文
plt.rcParams['font.sans-serif'] = ['SimHei']
# 用来正常显示负号
plt.rcParams['axes.unicode_minus'] = False


if __name__ == '__main__':
    plt.title(u"中文测试")
    plt.xlabel(u'X轴')
    plt.ylabel(u'Y轴')
    plt.plot(np.arange(5), np.arange(5))
    plt.show()

usage

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326803473&siteId=291194637