I am trying to color each bar based on a value, as explained here
I tried a simple code, and it worked:
df=pd.DataFrame([95,94,99,90,89,91,92,85], columns=["Value"])
mask1 = df.Value < 90
mask2 = df.Value >= 90
bar=plt.bar( df.index[mask1],df.Value[mask1], color='red')
bar=plt.bar( df.index[mask2],df.Value[mask2], color='blue')
plt.hlines(90,0,7);
The problem is that when I apply to my dataset the order of the columns are changed. The original data is:
. %REALIZADAS
MÊS
JANEIRO 96
FEVEREIRO 86
MARÇO 94
ABRIL 96
MAIO 85
JUNHO 92
JULHO 96
AGOSTO 92
SETEMBRO 94
OUTOBRO 94
NOVEMBRO 97
DEZEMBRO 94
And I plotted it using
plt.bar(coleta.index, coleta['%REALIZADAS'])
plt.xticks(rotation=90)
results in this chart:
And I tried this code:
mask1= coleta["%REALIZADAS"]>=90
mask2= coleta["%REALIZADAS"]<90
bar=plt.bar(coleta.index[mask1], coleta['%REALIZADAS'][mask1], color="blue")
bar=plt.bar(coleta.index[mask2], coleta['%REALIZADAS'][mask2], color="red")
plt.xticks(rotation=90)
plt.hlines(90, 0,11, color='black')
But resulted in this chart:
How can I keep the order of the columns?