👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I generated a bar plot, how can I display the value of the bar on each bar?
Current plot:
What I am trying to get:
My code:
import os
import numpy as np
import matplotlib.pyplot as plt
x = [u"INFO", u"CUISINE", u"TYPE_OF_PLACE", u"DRINK", u"PLACE", u"MEAL_TIME", u"DISH", u"NEIGHBOURHOOD"]
y = [160, 167, 137, 18, 120, 36, 155, 130]
fig, ax = plt.subplots()
width = 0.75 # the width of the bars
ind = np.arange(len(y)) # the x locations for the groups
ax.barh(ind, y, width, color="blue")
ax.set_yticks(ind+width/2)
ax.set_yticklabels(x, minor=False)
plt.title("title")
plt.xlabel("x")
plt.ylabel("y")
#plt.show()
plt.savefig(os.path.join("test.png"), dpi=300, format="png", bbox_inches="tight") # use format="svg" or "pdf" for vectorial pictures
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from How to display the value of the bar on each bar with pyplot.barh(), check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano How to display the value of the bar on each bar with pyplot.barh()
- Deutsch How to display the value of the bar on each bar with pyplot.barh()
- Français How to display the value of the bar on each bar with pyplot.barh()
- Español How to display the value of the bar on each bar with pyplot.barh()
- Türk How to display the value of the bar on each bar with pyplot.barh()
- Русский How to display the value of the bar on each bar with pyplot.barh()
- Português How to display the value of the bar on each bar with pyplot.barh()
- Polski How to display the value of the bar on each bar with pyplot.barh()
- Nederlandse How to display the value of the bar on each bar with pyplot.barh()
- 中文 How to display the value of the bar on each bar with pyplot.barh()
- 한국어 How to display the value of the bar on each bar with pyplot.barh()
- 日本語 How to display the value of the bar on each bar with pyplot.barh()
- हिन्दी How to display the value of the bar on each bar with pyplot.barh()
Shanghai | 2023-03-21
I was preparing for my coding interview, thanks for clarifying this - How to display the value of the bar on each bar with pyplot.barh() in Python is not the simplest one. I am just not quite sure it is the best method
Warsaw | 2023-03-21
Thanks for explaining! I was stuck with How to display the value of the bar on each bar with pyplot.barh() for some hours, finally got it done 🤗. Checked yesterday, it works!
California | 2023-03-21
Maybe there are another answers? What How to display the value of the bar on each bar with pyplot.barh() exactly means?. I just hope that will not emerge anymore