将文本添加到 Pandas 数据框图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/22287827/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
add text to pandas dataframe plot
提问by Shai Zarzewski
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?
我想在情节中添加两个字符串(val + name)我该怎么做?
btw if there's a better way to do the plot i'll like to know that
顺便说一句,如果有更好的方法来绘制情节,我想知道
回答by Paul H
You can use ax.text()or ax.annotate()
您可以使用ax.text()或ax.annotate()
ax.textaccepts the the x-coord and y-coord (in data coordinates) and then the string  as arguments. ax.annotateis a little more complicated: http://matplotlib.org/1.3.1/users/annotations_intro.html
ax.text接受 x 坐标和 y 坐标(在数据坐标中),然后是字符串作为参数。ax.annotate有点复杂:http: //matplotlib.org/1.3.1/users/annotations_intro.html

