我想为matplotlib自动生成的marker
点添加标签,但我不知道如何找到这些点(下面加粗的i
和j
)来自我的Pandas DataFrameGroupby对象。我创建图表的命令是
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
标签。
这是带有标记点的附加图像:
答案 0 :(得分:1)
很难确定,因为您没有提供数据帧的内容。将来,请考虑生成Minimal, Complete, and Verifiable example
话虽如此,我认为这正是您所寻找的:
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="->"))