gpt4 book ai didi

python - Seaborn/Matplotlib - 仅在 FacetGrid 中显示某些 X 值

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:09 25 4
gpt4 key购买 nike

我正在尝试创建一个图表方面,以秒为单位显示一段时间内的总得分。 X 轴是以秒为单位的时间,y 轴是总分。

如您所见,我通过 xlim 将输出限制为 2 1/2 分钟。

我想做的是仅在 x 轴上每 30 秒显示一次值(即 30、60、90、120、150)。我仍然想显示(例如)10 和 15 的值图表上的秒,只是不在 x 轴上的标签上。

如何修改下面的代码来做到这一点?一直在尝试各种形式的 xticks 和 xlabel,但就是无法弄清楚.. Google 也不是我的 friend ..

非常感谢一些帮助

谢谢

df = pd.DataFrame({'Subject': ['Math', 'Math', 'Math','Math', 'Math', 'Math', 'Math','Math', 'Math', 'Math','English', 'English', 'English','English', 'English', 'English', 'English','English', 'English', 'English'], 
'timeinseconds': [1, 10, 15, 30, 45, 60, 90, 120, 140, 150,1, 10, 15, 30, 45, 60, 90, 120, 140, 150],
'totalscore': [.2, .3, .4, .37, .45, .55, .60, .54, .63, .72,
.4, .34, .23, .52, .56, .59, .63, .66, .76, .82]})

g = sns.FacetGrid(df, col="Subject", col_wrap=5, size=3.5, ylim=(0, 1),xlim=(0,360))
g = g.map(sns.pointplot, "timeinseconds", "totalscore", scale=.7)

最佳答案

这将解决您的问题:

g = (g.map(sns.pointplot, "timeinseconds", "totalscore", scale=.7)
.set(xticks=[3, 5, 6, 7, 9], xticklabels=[30, 60, 90, 120, 150]))

xticks 表示要放置标签的位置(编号从 0n-1,其中 n 是原始刻度数),xticklabels 是实际标签。

您当然可以找到一种减少硬编码的方法。

关于python - Seaborn/Matplotlib - 仅在 FacetGrid 中显示某些 X 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39918424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com