I am trying to change the colors bar in matplotlib for the last colors to be blue. 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])
它丢失了两倍[[]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.