我创建了一个pointplot()
我无法更改 x 轴限制。虽然我的数据仅包含 9 个月,但我想在轴上显示所有 12 个月。
fig,ax = plt.subplots(figsize=(12,4))
sns.pointplot(data=tr_df, x='Month', y='numOfTrips', hue='Year', ax=ax, palette='nipy_spectral')
# sns.plt.xlim(0, 12) # AttributeError: module 'seaborn' has no attribute 'plt'
# ax.set_xlim=(0, 12) # does nothing
ax.set(xlim=(0, 12))
ax.set(title="Number of trips each month")
我究竟做错了什么?
编辑:用于创建绘图的数据
Year Month numOfTrips
0 2011 7 2608
1 2011 8 33579
2 2011 9 34756
3 2011 10 31423
4 2011 11 20746
5 2012 3 12240
6 2012 4 37637
7 2012 5 46056
8 2012 6 48315
9 2012 7 61659
10 2012 8 75443
11 2012 9 73012
12 2012 10 67372
13 2012 11 40862
14 2013 4 56625
15 2013 5 88105
16 2013 6 99301
17 2013 7 92504
恕我直言,seaborn 的pointplot
不是您正在寻找的那种情节。
我建议一个简单的lineplot
,然后您尝试将 xlims 按预期工作:
fig,ax = plt.subplots(figsize=(12,4))
sns.lineplot(data=tr_df, x='Month', y='numOfTrips', hue='Year', ax=ax, palette='nipy_spectral')
ax.set(xlim=(0, 12))
ax.set(title="Number of trips each month")
leads to
但是,我还建议将此上下文中的 xticks 设置为某个列表12值,而 0...12 有13... ;-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)