0

I am trying to plot a bar char with python. Following is my code. I am getting 0 value for each of my bar.

from __future__ import division
import matplotlib.pyplot as plt
import numpy as np

x = [0,1,2,3,4,5,6,7,8,9,10,11,12]
freq = [0.93, 0.87,0.86,0.87,0.93,0.84,0.74,0.79,0.78,0.95,0.88,0.8, 0.71]

width = 0.5 # width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x, freq, width, color='r')

ax.set_ylim(0,1)
ax.set_ylabel('auc-roc')

ax.set_xticks(np.add(x,(width/2.2))) # set the position of the x ticks
ax.set_xticklabels(('X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'X10', 'X11', 'X12', 'X13'))

def autolabel(rects):

    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., 1.0*height,
            '%d' % (height),
            ha='center', va='bottom')

autolabel(rects1)

plt.show()

Image with 0 bar values

1 Answer 1

2
'%d' % (height),

I think that this maps value to integer. In your case values are runded to 0.

Use %f or rather %.2f.

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

That was just a change of format. Change %d to %.2f and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.