[英]Plotting monthly data in Seaborn lineplot in different order
我正在寻找 plot 线图中的每月空气质量数据 Seaborn。 由于空气质量最差的月份是 11 月至 2 月,我希望将这些月份放在线图的中间。 我的问题是,这可以做到吗?
concentration vs month
axes[1] = sns.lineplot(ax=axes[1],
data=df_month,
#x=df['date'],
x=df_month['month'],
y=df_month['monthly mean'],
color='red',
linewidth=1.5,
#hue=hue,
palette="hls")
这个就是目前正在生产的plot
我尝试对月份值进行分类排序,但这返回了一个空白图表
df_month['month'] = pd.Categorical(df_month['month'],
categories=['6', '7', '8', '9', '10', '11', '12', '1',
'2', '3', '4', '5'],
ordered=True)
这是我正在尝试的数据 plot
location month monthly mean
1 Location A 3 87.98375
2 Location A 4 45.91740741
3 Location A 5 21.71923077
4 Location A 6 12.84966667
5 Location A 7 10.09612903
6 Location A 8 13.80387097
7 Location A 9 18.598
8 Location A 10 37.799
9 Location A 11 108.124
10 Location A 12 71.87241379
11 Location A 1 138.5916129
12 Location A 2 55.36103448
这是我想要实现的 excel 图
感谢您的帮助@JohanC。 我没有意识到我必须在应用 pd.Categorical 后对值进行排序。 (我也意识到我错误地将月份数字放在引号中)
# set categorical order
df_month['month'] = pd.Categorical(df_month['month'], categories=[6, 7, 8, 9,
10, 11, 12, 1, 2, 3, 4, 5], ordered=True)
df_month.sort_values('month', inplace=True)
一旦我这样做了,我就可以使用你对 sns.pointplot 的有用建议来实现我想要的图表。
# concentration vs month
axes[1] = sns.pointplot(ax=axes[1],
data=df_month,
x='month',
y='monthly max mean',
color='red',
scale =0.6,
markers='',
order=df_month['month'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.