ValueError: matplotlib display text must have all code points 《 128 or use Unicode strings解决方案

在python的matplotlib包中运行一个简单的画图demo

import matplotlib.pyplot as plt

xlist = [1,2,3,4]
ylist = [5,6,7,8]
plt.plot(xlist, ylist)
plt.xlabel("x参数")
plt.xlabel("y参数")
plt.show()

运行之后,报错:ValueError: matplotlib display text must have all code points < 128 or use Unicode strings

解决方案很简单

plt.xlabel(u"x参数")
plt.xlabel(u"y参数")

将中文见面加上u,更改字符编码即可

猜你喜欢

转载自blog.csdn.net/qq_18999357/article/details/84581629