[英]Changing some bars colors
I am trying to change the colors bar in matplotlib for the last colors to be blue. 我正在尝试将matplotlib中的颜色栏更改为最后一种颜色为蓝色。 But in the end they are all green. 但最后它们都是绿色的。
colors = ['blue' if (i>=19 and i<23) else 'green' for i in
list(range(24))]
df.plot(y='Jan',kind='bar',edgecolor='none',figsize=(16,8),linewidth=2, color=colors)
plt.legend(prop={'size':16})
ax = plt.gca()
plt.gcf().autofmt_xdate()
ax.set_xticklabels(df.index)
plt.tight_layout()
plt.savefig('myimage.svg', format='svg', dpi=1200)
plt.show()
what am I missing? 我想念什么? I followed similar tutorials 我遵循了类似的教程
Here is some data to test the example 这是一些数据来测试示例
sales = [('Jan', [150, 200, 50,150, 200, 50,150, 200, 50, 150, 200, 50,150, 200, 50,150, 200, 50,150, 200, 50,150, 200, 50])]
df = pd.DataFrame.from_items(sales)
df.plot(y='Jan',kind='bar',edgecolor='none',figsize=(16,8),linewidth=2, color=[colors])
它丢失了两倍[[]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.