将字符串转换为float时无效的rgb arg'x'

时间:2017-07-11 18:38:52

标签: python string numpy matplotlib

我试图绘制数据....它们包含逗号,并在将它们转换为浮点数后,我得到错误。

数据样本'0,8750044'

这是脚本的一部分

for row in data:
    xvalue.append(row[0])
    yvalue.append(float(row[1].replace(',','.')))
    yerro.append(float(row[3].replace(',','.')))
 plt.errorbar( xvalue, yvalue, yerr=yerro, label='error', ecolor='xkcd:salmon', elinewidth=1.5, capsize=5, errorevery=1)
  ax= plt.gca()
  ax.set_xlim([0,110])

我收到以下错误;

    ValueError: to_rgba: Invalid rgba arg "x"
     to_rgb: Invalid rgb arg "x"
     could not convert string to float: 'x'

我打印了所有3行......结果在这里

 row 1 ->  [35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 
95.0, 100.0] 

 row 2 ->   [1.117702, 0.9835718, 0.8750044, 0.787232, 0.7157482, 0.6559332, 0.6059028, 
0.562483, 0.5250466, 0.4921584, 0.4633862, 0.4377058, 0.4145508, 0.3934362] 

 row 3 ->   [0.007960752, 0.000118388, 0.000210205, 0.000125529, 0.0004768, 
0.000318498, 0.000239502, 8.58429e-05, 0.000172489, 0.000163555, 0.00041402, 
0.000548504, 0.000116907, 0.000159586]

如果行很好......那么有一些错误的plt.errorbar() 有人可以解释出了什么问题,我该如何解决?

1 个答案:

答案 0 :(得分:2)

It appears that you are using an older version of matplotlib that does not have the 'xkcd' colors defined. Using ecolor='xkcd:salmon' works in matplotlib 2.0.2. Either update matplotlib to a newer version, or use a different color (e.g. ecolor='salmon' should work).