我有下面的代码。我正在尝试绘制一个图表。
目前,X轴未按升序进行标记:28-37.99应该在38-47.99之前,但我不确定如何做到这一点。
会如此感激你的帮助!
fig, axes = plt.subplots(nrows=2,figsize=(15, 15))
fig.tight_layout(pad=10)
newerdf = newdf.copy()
bins = [18,28,38,48,58]
names = ['<28','28-37.99','38-47.99','48-57.99','58+']
d = dict(enumerate(names, 1))
newerdf['age'] = np.digitize(newerdf['age'], bins)
newerdf['age'] = newerdf['age'].map(d)
Graph1 = sns.lineplot(data=newerdf,x="age", y="distance",errorbar ='se',err_style='bars',ax=axes[0])
Graph2 = sns.lineplot(data=newerdf,x="age", y="duration",errorbar ='se',err_style='bars',ax=axes[1])
Graph1.set_xlabel( "Age",labelpad = 10,weight='bold')
Graph2.set_xlabel( "Age",labelpad = 10,weight='bold')
Graph1.set_ylabel("Wayfinding Distance",labelpad = 10,weight='bold')
Graph2.set_ylabel("Wayfinding Duration",labelpad = 10,weight='bold')
1条答案
按热度按时间f8rj6qna1#
这里的基本思想是seborn中的x_axis不能解释数据的给定顺序