【问题标题】:Annotate points in Seaborn stripplot with Pandas dataframe使用 Pandas 数据框注释 Seaborn stripplot 中的点
【发布时间】:2017-10-20 00:47:59
【问题描述】:

是否可以在 seaborn 的条形图上标注每个点?我的数据在熊猫数据框中。我意识到注释适用于 matplotlib,但在这种情况下我还没有发现它可以工作。

【问题讨论】:

  • matplotlib 的annotate 据我所知应该可以工作,seaborn 是基于 matplotlib,你能展示一些你的尝试代码吗?

标签: pandas matplotlib seaborn annotate


【解决方案1】:

您只需要返回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')

【讨论】:

  • 这不是我的意思。我想将这些点更改为在另一列中找到的单词。这可能吗?
  • 你想把数据点变成单词吗?您能否更新问题以准确说明您希望情节看起来像什么,并可能包括您所描述的另一个情节的示例?如果您的目标是用文字/文本交换数据点,则可能是 pandas stripplot 不是要走的路。
猜你喜欢
  • 2019-08-01
  • 2014-01-28
  • 2019-01-12
  • 2021-12-22
  • 1970-01-01
  • 2017-08-26
  • 1970-01-01
  • 2020-05-14
  • 1970-01-01
相关资源
最近更新 更多