多个颜色分类散点图python无法将字符串转换为float

时间:2018-02-26 05:47:03

标签: python matplotlib

我正在尝试将一组数据绘制成一个图。我将数据加载到元组列表中,每个元素都是元组(time_list,data_list)。

我想在一个图中用不同颜色绘制所有数据日的散点图,x轴表示时间,y轴表示数据。

但是我收到错误消息:无法将字符串转换为float

这就是我所做的:

labels = ['S', 'M']
colors = ['pink','orange']

plt.figure()
plt.title ('Daily Call Volumn By Day')

count = 0
for i in totalcalls:
    xval = i[0]
    yval = i[1]
    plt.scatter(x = xval, y = yval, color = colors[count], label = labels[count])
    count += 1
plt.legend(loc='upper left')
plt.show()

元组列表如下所示:

totalcalls =
[(['2004-05-02 00:00:00',
   '2004-05-09 00:00:00',
   '2004-05-16 00:00:00',
   '2004-05-23 00:00:00',
   '2004-05-30 00:00:00',
   '2004-06-06 00:00:00',
   '2004-06-13 00:00:00',
   '2004-06-20 00:00:00',
   '2004-06-27 00:00:00',
   '2004-07-04 00:00:00',
   '2004-07-11 00:00:00',
   '2004-07-18 00:00:00',
   '2004-07-25 00:00:00',
   '2004-08-01 00:00:00',
   '2004-08-08 00:00:00',
   '2004-08-15 00:00:00',
   '2004-08-29 00:00:00'],
  [464.42424242424244,
   385.63636363636363,
   401.93939393939394,
   363.60606060606062,
   371.30303030303031,
   341.45454545454544,
   392.72727272727275,
   423.4848484848485,
   390.93939393939394,
   396.75757575757575,
   410.75757575757575,
   400.84848484848487,
   376.72727272727275,
   376.15151515151513,
   430.4848484848485,
   464.09090909090907,
   379.36363636363637]),
 (['2004-05-03 00:00:00',
   '2004-05-10 00:00:00',
   '2004-05-17 00:00:00',
   '2004-05-24 00:00:00',
   '2004-05-31 00:00:00',
   '2004-06-07 00:00:00',
   '2004-06-14 00:00:00',
   '2004-06-21 00:00:00',
   '2004-06-28 00:00:00',
   '2004-07-05 00:00:00',
   '2004-07-12 00:00:00',
   '2004-07-19 00:00:00',
   '2004-07-26 00:00:00',
   '2004-08-02 00:00:00',
   '2004-08-09 00:00:00',
   '2004-08-16 00:00:00',
   '2004-08-23 00:00:00',
   '2004-08-30 00:00:00'],
  [441.5151515151515,
   418.84848484848487,
   387.27272727272725,
   351.72727272727275,
   394.72727272727275,
   373.18181818181819,
   384.69696969696969,
   399.90909090909093,
   362.06060606060606,
   372.75757575757575,
   383.57575757575756,
   386.93939393939394,
   387.21212121212119,
   369.4848484848485,
   410.06060606060606,
   428.27272727272725,
   419.87878787878788,
   389.030303030303])
]

似乎逻辑是正确的,但我无法解决这个问题。 谢谢!

0 个答案:

没有答案