Using Matplotlib
, I display a dictionary chart. But I want to have the features in the vertical axis. This does not happen by changing the order of the first and second plt.bar
parameters.
my_dictionary = {'F1': 0.0, 'F2': -0.03137518153387725, 'F3': -0.028483522708153908, 'F4': -0.04285443514756063, 'F5': 0.007765016154692321, 'F6': 0.003007286684430399, 'F7': 0.0033222336382515774, 'F8': 0.0013582396102663208, 'F9': -0.0025918156002548154, 'F10': 0.0202258302015568, 'F11': 0.030016293782106906, 'F12': 0.000827900819205335, 'F13': -0.010119661798570101, 'F14': -0.014028783493522351, 'F15': -0.0015247180908278396, 'F16': -0.004395984305092304, 'F17': 0.005053514422172792}
flag1 = 0
flag2 = 0
for i in my_dictionary.items():
if i[1] <= -0.002:
if flag1 == 0:
plt.bar(i[0], i[1], width=0.8, color='orange', label='L')
flag1 = 1
else:
plt.bar(i[0], i[1], width=0.8, color='orange')
elif i[1] >= 0.002:
if flag2 == 0:
plt.bar(i[0], i[1], width=0.8, color='purple', label='H')
flag2 = 1
else:
plt.bar(i[0], i[1], width=0.8, color='purple')
plt.grid()
plt.xticks(rotation='vertical')
plt.legend()
plt.show()