-3

This code gives me a bar chart but I also want to insert the percentage, how will I go about it?

Hipertension_factor = appointments.groupby(['No-show'])['Hipertension'].count()
Hipertension_factor.plot(kind = 'bar', title = 'Hipertension')
plt.xlabel('No-show', fontsize = 18)
plt.ylabel('Hipertension', fontsize = 18)
sahasrara62
  • 10,069
  • 3
  • 29
  • 44
chinelo Okafor
  • 269
  • 3
  • 2

1 Answers1

0

We cannot provide code to solve your problem, but there are many ways to annotate plots in matplotlib (which I will assume you are using) as shown here

https://matplotlib.org/gallery/text_labels_and_annotations/annotation_demo.html#sphx-glr-gallery-text-labels-and-annotations-annotation-demo-py

Where a basic example is:

ax.annotate('straight',
    xy=(0, 1), xycoords='data',
    xytext=(-50, 30), textcoords='offset points',
    arrowprops=dict(arrowstyle="->"))

You will just need to calculate the percentages using a standard count or what you want/total count of possibilities formula and then you can plot the results using the same x,y as you used to create the bar graph, and include a string with the percentage you just calculated (replacing 'straight' in the example above). This question also does not have a direct answer because you may want to annotate slightly off your bars which will be different than plotting exactly on your bars...

Reedinationer
  • 5,661
  • 1
  • 12
  • 33