0
import os
import numpy as np
import matplotlib.pyplot as plt

x = ['Buildings', 'Forest', 'Glaciar', 'Moutain', 'Sea', 'Street']
y = [33.41, 90.72, 37.79, 60.95, 51.76, 59.88]


x_pos = [i for i, _ in enumerate(x)]

for i, v in enumerate(y):
    y.text(v + 3, va='center', str(y), color='blue', fontweight='bold')

plt.barh(x_pos, y)


plt.ylabel("Cenários")
plt.xlabel("Percentagem de acerto %")
plt.title("Taxa de Reconhecimento")

plt.yticks(x_pos, x)

plt.show()

So im new to python, but i want to place does y values at the end of each bar I found come solutions but any of them working, can someone help me pls? thnx

  • 1
    have a look on here https://matplotlib.org/3.1.0/gallery/pyplots/fig_axes_labels_simple.html – Terchila Marian Apr 29 '20 at 17:16
  • 1
    Does this answer your question? [How to display the value of the bar on each bar with pyplot.barh()?](https://stackoverflow.com/questions/30228069/how-to-display-the-value-of-the-bar-on-each-bar-with-pyplot-barh) – DavidG Apr 30 '20 at 09:55

1 Answers1

1

You need to use the x and y position and plt.text

plt.barh(x_pos, y)

for i, v in enumerate(y):
    plt.text(v + 3,  i, v, va='center', color='blue', fontweight='bold')

enter image description here

Sheldore
  • 37,862
  • 7
  • 57
  • 71