用python绘制图时候出现Text reading control character must be a single unicode character or None; but got: ' '这个错误
from pylab import *
class picture():
def init(self,data_location,delimiter):
self.data_location = data_location
self.delimiter = delimiter
def draw(self):
txt_array = np.loadtxt(self.data_location, skiprows=1, delimiter=self.delimiter)
mpl.rcParams['font.sans-serif'] = ['SimHei'] # 添加这条可以让图形显示中文
x_axis_data = txt_array.T[0]
y_axis_data = txt_array.T[1]
y_axis_data1 = txt_array.T[3]
# plot中参数的含义分别是横轴值,纵轴值,线的形状,颜色,透明度,线的宽度和标签
plt.plot(x_axis_data, y_axis_data, 'ro-', color='#4169E1', alpha=0.8, linewidth=1, label='年平均气温')
# 显示标签,如果不加这句,即使在plot中加了label='一些数字'的参数,最终还是不会显示标签
plt.plot(x_axis_data, y_axis_data1, 'ro-', alpha=0.8, linewidth=1, label='年均日最低气温')
plt.legend(loc="upper right")
plt.title('气温时间变化图')
plt.xlim(1945, 2018)
plt.ylim(5, 15)
plt.xlabel('年份')
plt.ylabel('温度')
plt.savefig('./polygon.png', dpi=300)
plt.show()
picture = picture("C:\Users\g'g'g\Desktop\python\54511.txt",delimiter=' ')
picture.draw()
报错内容为Text reading control character must be a single unicode character or None; but got: ' '
谢谢各位的帮忙
"C:\Users\g'g'g\Desktop\python\54511.txt",这个路径包含了非法字符(')吧?
不知道你这个问题是否已经解决, 如果还没有解决的话: