# Having and issue plotting horizontal chart

So for some weird reason I can't manage to fix the plotting issue

Any suggestions?

from sklearn.metrics import confusion_matrix

List = []
for i in range(len(model)):
cm = confusion_matrix(Y_test, model[i].predict(X_test))

TN = cm[0][0]
TP = cm[1][1]
FN = cm[1][0]
FP = cm[0][1]

List.append(((TP + TN) / (TP + TN + FN + FP))*100)

print()

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
bars = ('Logistic', 'K Nearest Neighbor', 'K Nearest Neighbor', 'Support Vector Machine ', 'Support Vector Machine ','Support Vector Machine ','Support Vector Machine ' )
percentage = np.array([List[0], List[1], List[2], List[3],List[4],List[5],List[6]])

new_labels = [i+'  {:.2f}%'.format(j) for i, j in zip(bars, percentage)]

plt.barh(bars, percentage, color='lightskyblue', edgecolor='blue')
plt.yticks(range(len(bars)), new_labels)
# Show graphic
plt.show()

• Hello @Omerlewitz, welcome to the site. Your answer seems quite vague, have a look here to see how to ask better questions. Nevertheless, could you describe better what your desired outcome would be? – Bruno Lubascher Apr 17 at 18:14
• each algorithm will be filled to the percentage it should be and the bar will be blue Like the bottom ones – Omerlewitz Apr 17 at 18:23

You have to change one line in your code.

This

plt.barh(bars, percentage, color='lightskyblue', edgecolor='blue')

should become this

plt.barh(range(len(bars)), percentage, color='lightskyblue', edgecolor='blue')

What you are changing is the y position of your bars. If you look at your original bars there are only 3 values there, so bars were overlapping.

Once you change that to range(len(bars)) you are using the same tick values that you set in plt.yticks(range(len(bars)), new_labels).