ValueError(“颜色块每个数据集必须具有一种颜色")? [英] ValueError("color kwarg must have one color per dataset")?

查看:34
本文介绍了ValueError(“颜色块每个数据集必须具有一种颜色")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是简单地将数据保存到文件中并读出它们,然后绘制直方图.但是,尽管我实际上对原始代码没有任何更改,但似乎出现了这个错误.谁能告诉我怎么了?非常感谢.

I just simply save the data into files and read them out and then draw histogram. However, it appears this mistake though I changed nothing from the original code actually. Could anyone tell me what's wrong? Thanks a lot.

这是hist()的代码

Here is the code for hist()

f_120 = plt.figure(1)
plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.axvline(x = 30, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 60, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend()

plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.title('Cumulative histogram: time elapsed \n before questions receive answer (first 2 hrs)')
plt.ylim(0,1)
plt.xlim(0,120)

f_120.show()

f_2640 = plt.figure(2)
plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.axvline(x = 240, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '4 hours')
plt.axvline(x = 1440, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 day')
plt.legend(loc= 4)

plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.title('Cumulative histogram: time elapsed \n before questions receive answer (first 48)')
plt.ylim(0,1)
plt.xlim(0,2640)

f_2640.show()

错误的全文:

 plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step",
          cumulative = True, color = 'b',label = 'first answer')

  File "C:\Python26\lib\site-packages\matplotlib\pyplot.py", line 2160, in hist
    ret = ax.hist(x, bins, range, normed, weights, cumulative, bottom, histtype,
                  align, orientation, rwidth, log, color, label, **kwargs)

  File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 7606, in hist
    raise ValueError("color kwarg must have one color per dataset")

ValueError: color kwarg must have one color per dataset

推荐答案

这个问题是因为你已经将 tfirst_list 定义为一个 N 维数组.
例如:

This problem is because you have defined tfirst_list as a N-dimensional array.
For example:

tfirst_list = [1, 2, 3, 4, 5, 6, 7, 8]        #works
tfirst_list = [[1, 2, 3, 4], [5, 6, 7, 8]]    #produces the Exception you have

如果您使用的是 N 维数据(N datasets),那么 color 关键字参数(color kwarg)也必须是 N维度(每个数据集一种颜色).例如上面的案例:

If you are using N-dimensional data (N datasets), then the color keyword argument (color kwarg) must be also N-dimensional (one color per dataset). For example for the case above:

color = ['b', 'r']

这篇关于ValueError(“颜色块每个数据集必须具有一种颜色")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆