python - plt.text() 与分类变量而不是数字对齐
问题描述
我认为这应该是相当直截了当的,但我遇到了麻烦。我怎样才能将标签集中在一个类别而不是一个绝对位置上。
如何修改下面的代码以使此文本居中在“下”上方?
## plot strip plot
ax = sns.stripplot(x="Metric", y="Percent Error", data=dat,
jitter=0.3,
alpha = 0.5,
color = '#a54f7e',
linewidth=1,
edgecolor = '#a54f7e')
## Set title and axis
plt.title('Error Metrics')
ax.set(yscale="log")
## get median
lower_med = round(df['percent_error_lower'].median(),2)
## add text label
plt.text(0, lower_med,'{:.2f} \n (Median)'.format(lower_med))
解决方案
推荐阅读
- node.js - 在 Mongoose 中使用 ISODate 的正确方法是什么
- firebase - Firebase CLI:如何在 POST 请求中发送正文?
- c++ - 序列锁中的 atomic_thread_fence 要求
- python - Python作业涉及将字符串中的字符转换为数字
- excel - 如何在 INDEX(SMALL(IF 基于多个标准或仅基于用户输入的几个标准?
- google-sheets - 如果单元格日期介于 Google 表格中的某些日期之间,则显示周
- python - 删除列表中的后续重复项
- rx-java2 - 如何阻止 RXJava 2 在第一个错误之后发出更多错误?
- java - AspectJ:如何限制目标方面
- javascript - 单击任何菜单项时如何关闭汉堡菜单