【发布时间】:2018-02-19 11:00:03
【问题描述】:
所以我的数据看起来像
Manufacturer Mean
0 DAF 57.036199
1 Fiat 42.296814
2 Ford 54.546769
3 Iveco 41.678711
4 MAN 50.764308
5 Mercedes Benz 49.093340
6 Renault 47.384080
7 Scania 46.317282
8 Volkswagen 50.938158
9 Volvo 43.382830
我正在尝试使用上述数据绘制条形图。我希望 48 以上的值有不同的颜色,底部的 3 有不同的颜色。我尝试使用下面的代码,但它给了我以下错误:
TypeError: unsupported operand type(s) for -: 'str' and 'float'
我为制作图表而编写的代码:
plt.figure()
plt.bar(meansOfRoadGoingVehicles_sort['Manufacturer'], meansOfRoadGoingVehicles_sort['Mean'])
plt[0:7].set_color('b')
plt[6].set_color('grey')
plt[8:11].set_color('r')
plt.show()
【问题讨论】:
-
试试
df.plot.bar()或df.set_index('Manufacturer').plot.bar() -
如果有任何答案满足你的解决方案,请在左侧用绿色勾号标记。
标签: python pandas matplotlib graph-coloring