代码如下:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(x_data, y_data, color='tab:blue')
ax.plot(fx_data, fy_data, color='tab:orange')
ax.plot(zx_data, zy_data, color='tab:red')
# create the events marking the x data points
xevents1 = EventCollection(x_data, color='tab:blue', linelength=0.05)
xevents2 = EventCollection(fx_data, color='tab:orange', linelength=0.05)
xevents3=EventCollection(zx_data,color='tab:red',linelength=0.05)
# create the events marking the y data points
yevents1 = EventCollection(y_data, color='tab:blue', linelength=0.05,
orientation='vertical')
yevents2 = EventCollection(fy_data, color='tab:orange', linelength=0.05,
orientation='vertical')
yevents3=EventCollection(zy_data,color='tab:red',linelength=0.05,orientation='vertical')
# add the events to the axis
ax.add_collection(xevents1)
ax.add_collection(xevents2)
ax.add_collection(xevents2)
ax.add_collection(yevents1)
ax.add_collection(yevents2)
ax.add_collection(xevents3)
ax.add_collection(yevents3)
# set the limits
ax.set_xlim([0, 1])
ax.set_ylim([0, 1])
ax.set_title('line plot with data points')
# display the plot
plt.show()
报错:ValueError: could not convert string to float: '2020-02-05'
问题:我没有设置要将数据变为float的代码呀?请问是哪里出错了呢?还是说用matplotlib画图用的数据都会自动转成float?