python - How can I add points onto a seaborn barplot?
问题描述
How can I put points onto a seaborn
bar plot? The following code produces the bar plot.
import matplotlib.pyplot as plt
import seaborn
import matplotlib
matplotlib.use('TkAgg')
seaborn.set_context('talk')
data_df = pandas.DataFrame([3, 1, 2, 4], index=['a', 'b', 'c', 'd']).transpose()
points_df = pandas.DataFrame([3.5, 0.5, 1.75, 4.25], index=['a', 'b', 'c', 'd']).transpose()
plt.figure()
seaborn.barplot(data=data_df)
plt.show()
How can I now add the data in points_df
as red points on this graph?
解决方案
这是你想要的?
data_df = pd.DataFrame([3, 1, 2, 4], index=['a', 'b', 'c', 'd']).transpose()
points_df = pd.DataFrame([3.5, 0.5, 1.75, 4.25], index=['a', 'b', 'c', 'd']).transpose()
plt.figure()
sns.barplot(data=data_df)
sns.scatterplot(data=points_df.T, legend=False, zorder=10)
出于某种原因,我不得不改变zorder
点的,否则有些会被隐藏在栏杆后面
推荐阅读
- c# - 在 Azure Functions V1 中反序列化 json 时出错
- jquery - columnDefs 不能用于禁用对某些列的搜索?
- javascript - 在每个点击事件上向前移动一个圆圈 100 像素
- linux - 即使定义了 IFS 也无法使用双倍空格移动文件
- filemaker - FM18 / FM18 服务器更新后 Filemaker 导入记录 GUI 空白
- django - TypeError:kitty() 得到了一个意外的关键字参数“startdate”
- django - 防止 Redis/Celery 计划任务被多次处理 - Heroku 上的 Django
- java - 您可以重新平衡未知大小的不平衡拆分器吗?
- javascript - cesiumWorkerBootstrapper 使用 RequireJS importScripts 时出错
- c# - 如何将 CSV 文件拆分为多个部分