[英]Adding multiple labels at once for matplotlib subplots from pandas dataframe
[英]Adding labels to points from a Pandas dataframe object using Matplotlib
我想将标签添加到由matplotlib自动生成的marker
点上,但是我不知道如何从我的Pandas DataFrameGroupby对象中找到这些点(下面的粗体i
和j
)。 我创建图形的命令是
for x, group in graph:
t = group.plot(x="CompressorSpeed", y="ratio", marker='o').set_title(x)
plt.annotate('This is awesome', xy=( **i**, **j** ), arrowprops=dict(arrowstyle="->"))
plt.savefig(pp, format="pdf")
图所在的位置(而csvdata
是从read_csv(...)
创建的Pandas DataFrame对象)
graph=csvdata.groupby("CompressorAlgo", as_index=False)
如果我对已知点进行硬编码,则可以验证是否创建了xy
标签。
这是带有标记点的附件图像:
确实很难确定,因为您没有提供数据框的内容。 将来,请考虑生成一个最小,完整和可验证的示例
话虽如此,我认为这是您要寻找的:
for x, group in graph:
t = group.plot(x="CompressorSpeed", y="ratio", marker='o').set_title(x)
for i,j in group[["CompressorSpeed","ratio"]].values:
plt.annotate('This is awesome', xy=(i,j), arrowprops=dict(arrowstyle="->"))
plt.savefig(pp, format="pdf")
另一种实现相同目标但更容易阅读的方式是:
for z,row in group.iterrows():
plt.annotate('This is awesome', xy=(row["CompressorSpeed"],row["ratio"]), arrowprops=dict(arrowstyle="->"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.