在Matplotlib

时间:2016-05-11 14:48:06

标签: excel matplotlib plot scatter

我正在为类似于此处的学校项目制作一个基本的散点图:How do I assign different dots different colors in a scatter plot made with MatPlotLib?

唯一的区别是我的数据是按发布日期的电影收入。因此,x轴是发布日期,y轴是收入。我有第三列,表明电影是中国还是外国,我想根据它分配红色和蓝色到散点。我使用链接中的方法将中文分配给' r'和外国的' b'。

然而plot_date似乎没有采用相同的c = colors参数。我收到这个错误:

fig,ax = plt.subplots() colors = [x2 [' Country and Region']。replace(' Foreign'' b')。replace(' China',& #39; R&#39)] mpl.pyplot.plot_date(x2 ['发布日期'],x2 ['总票房(百万)'],c =颜色) fig.autofmt_xdate()

ValueError:to_rgba:无效的rgba arg" [0 r 1 b 2 r 3 b 4 r 5 b 6 r 7 r 8 r 9 r 10 b 11 b 12 r 13 b 14 r 15 r 16 b 17 b 18 r 19 b 20 r 21 r 22 b 23 b 24 b 名称:国家和地区,dtype:对象]" rgba序列的长度应为3或4

我该如何解决这个问题?我应该使用另一种情节方法吗?我正在使用plot_date,因为我无法使用mpl.pyplot.scatter显示绘图。 (日期格式为mm / dd / yr,来自excel表。当我尝试.scatter时,它表示无效的类型提升。pic1pic2

0 个答案:

没有答案