add text to pandas dataframe plot
15,580
You can use ax.text()
or ax.annotate()
ax.text
accepts the the x-coord and y-coord (in data coordinates) and then the string as arguments. ax.annotate
is a little more complicated: http://matplotlib.org/1.3.1/users/annotations_intro.html
Author by
Shai Zarzewski
Updated on July 25, 2022Comments
-
Shai Zarzewski almost 2 years
I am plotting a dataFrame and I want to add information about the information (mean and std of the data) I am plotting the data this way:
df = pd.DataFrame({'type': lifeExpExcel['Country'], 'Infant mort. rate': lifeExpExcel['Infant mort. rate']}) ax = df.plot(kind='bar',x= lifeExpExcel['Country']) ax.set_ylabel('Infant mort. rate') ax.set_xlabel('Country') plt.show()
I want to add two string (val + name) to the plot How can I do this?
btw if there's a better way to do the plot i'll like to know that