1. 程式人生 > >ValueError: matplotlib display text must have all code points 《 128 or use Unicode strings解決方案

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,更改字元編碼即可