python Seaborn - annotations with pointplot

橙三吉。 提交于 2019-12-25 17:17:16

问题


I am using a pointplot in seaborn.

import seaborn as sns
sns.set_style("darkgrid")
tips = sns.load_dataset("tips")
ax = sns.pointplot(x="time", y="total_bill", hue="smoker",data=tips)

I would like to annotate all of the points. If there are points in between, I would like to label the points in between along with the line ends if that makes sense.

Thank you so much!


回答1:


The question is rather unspecific, but here is how to label each point in a pointplot, just as you would do with any other matplotlib scatter plot:

import matplotlib.pyplot as plt
import seaborn as sns

tips = sns.load_dataset("tips")
ax = sns.pointplot(x="time", y="total_bill", hue="smoker", data=tips)

for c in ax.collections:
    for of in c.get_offsets():
        ax.annotate("Label", of)

plt.show()



来源:https://stackoverflow.com/questions/46228180/python-seaborn-annotations-with-pointplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!