相关疑难解决方法(0)

在matplotlib Python中设置不同的条形颜色

假设我的条形图如下:

BarPlot

关于如何为每个载体设置不同颜色的任何想法?例如,AK是Red,GA是Green等等?

我在Python中使用Pandas和matplotlib

>>> f=plt.figure()
>>> ax=f.add_subplot(1,1,1)
>>> ax.bar([1,2,3,4], [1,2,3,4])
<Container object of 4 artists>
>>> ax.get_children()
[<matplotlib.axis.XAxis object at 0x6529850>, <matplotlib.axis.YAxis object at 0x78460d0>,  <matplotlib.patches.Rectangle object at 0x733cc50>, <matplotlib.patches.Rectangle object at 0x733cdd0>, <matplotlib.patches.Rectangle object at 0x777f290>, <matplotlib.patches.Rectangle object at 0x777f710>, <matplotlib.text.Text object at 0x7836450>, <matplotlib.patches.Rectangle object at 0x7836390>, <matplotlib.spines.Spine object at 0x6529950>, <matplotlib.spines.Spine object at 0x69aef50>, <matplotlib.spines.Spine object at 0x69ae310>, <matplotlib.spines.Spine object at 0x69aea50>]
>>> ax.get_children()[2].set_color('r') #You can also try to locate the first patches.Rectangle object instead of direct …
Run Code Online (Sandbox Code Playgroud)

python matplotlib bar-chart pandas

59
推荐指数
3
解决办法
14万
查看次数

标签 统计

bar-chart ×1

matplotlib ×1

pandas ×1

python ×1