I have data like this:
and then I want to create a visualization from the data I'm using this code :
# create the visualization of the data
fig = plt.figure(figsize=(10, 5)) #to set the figure size
fig.suptitle('Number of Transaction per day', fontsize=20) # to set the chart title and its font size
plt.xlabel('Day', fontsize=20) # to set the axis title and its font size
plt.ylabel('number of transaction', fontsize=20) # to set the axis title and its font size
x = eda_2['Day'] # load the data to be used for that axis
y = eda_2['number of transaction'] # load the data to be used for that axis
plt.bar(x, y, color = 'green') # to plot and select the line colour
plt.grid(color='darkgray', linestyle=':', linewidth=0.5)
plt.show() # to show the chart
and the result:
but I want to display the value of each bar, so I input this code:
for index, value in enumerate(y):
plt.text(value, index, str(value))
but it gives me an error Image size of 537447x362 pixels is too large. It must be less than 2^16 in each direction.
how to fix it?
CodePudding user response:
Use bar_label
function
bars = plt.bar(x, y, color='green') # to plot and select the line colour
# You may need to adjust the axis limits to fit the labels.
plt.bar_label(bars, padding=5, fontsize=20)