pandas - 使用 Pandas 数据框在 Seaborn stripplot 中注释点

标签 pandas matplotlib seaborn annotate

是否可以在 seaborn 的带状图上标注每个点?我的数据在 Pandas 数据框中。我知道注释适用于 matplotlib,但我发现它在这种情况下不起作用。

最佳答案

您只需要返回 axes 对象。下面的示例改编自 seaborn 文档 here :

import seaborn as sns

sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
sat_mean = tips.loc[tips['day'] == 'Sat']['total_bill'].mean()

ax = sns.stripplot(x="day", y="total_bill", data=tips)
ax.annotate("Saturday\nMean",
            xy=(2, sat_mean), xycoords='data',
            xytext=(.5, .5), textcoords='axes fraction',
            horizontalalignment="center",
            arrowprops=dict(arrowstyle="->",
                            connectionstyle="arc3"),
            bbox=dict(boxstyle="round", fc="w"),
            )
#ax.get_figure().savefig('tips_annotation.png')

png output

关于pandas - 使用 Pandas 数据框在 Seaborn stripplot 中注释点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44077661/

相关文章:

python - 非常嘈杂信号的 Scipy FFT 频率分析

python - 聚合具有相同索引的相同日期的行

python - 以另一个数据帧(Python Pandas)为条件索引/匹配数据帧中的日期?

python - Matplotlib - 看不见的边距切断了 3D 绘图数据?

pandas - 使用seaborn jointplot绘制2D numpy数组

python - 如何用最常见的值替换 pandas 列的值

python - matplotlib 文本未被剪裁

python - 在同一张图中,针对 matplotlib 中不同时间戳的多个 X 值绘制多个 Y 值?

python - Seaborn 箱线图水平线注释

python - 如何对齐重叠图中的直方图 bin 边缘