如何在 seaborn barplot 中订购条形图
How to order the bars in a seaborn barplot
在将问题作为重复问题关闭之前,请完整阅读问题。
我正在尝试在 job_title
、salary_in_usd
列上绘制条形图。
我使用了以下代码:
job_salary = df[['job_title', 'salary_in_usd']]
job_salary = job_salary.sort_values(['salary_in_usd']).reset_index(drop=True)
fig = plt.figure(figsize=(14,12))
sns.barplot('job_title',
'salary_in_usd',
data=job_salary,
ci=None)
plt.xticks(rotation=90);
这是我得到的输出,它没有完全排序。
我知道Whosebug上已经有一个与此相关的问题。但这根本没有帮助。我尝试了该问题上发布的所有答案,但无济于事。
我正在处理以下数据集:https://www.kaggle.com/saurabhshahane/data-science-jobs-salaries
job_title,salary_in_usd
Data Science Consultant,64369
Data Scientist,68428
Head of Data Science,85000
Head of Data,230000
Machine Learning Engineer,125000
Data Analytics Manager,120000
Research Scientist,450000
Data Analyst,46759
Data Engineer,74130
Data Science Engineer,127543
Manager Data Science,144000
Data Scientist,13400
Data Scientist,75966
Data Scientist,150000
Data Science Consultant,103000
Data Engineering Manager,153000
Data Engineer,90000
Data Analyst,90000
Data Analyst,60000
Data Scientist,50000
AI Scientist,12000
3D Computer Vision Researcher,5423
ML Engineer,270000
Applied Data Scientist,54376
Machine Learning Engineer,47681
Director of Data Science,154963
Data Engineer,28801
Data Analytics Engineer,110000
Research Scientist,83000
Machine Learning Engineer,250000
Data Analyst,59601
Data Analyst,80000
Data Analyst,10000
Machine Learning Engineer,138000
Data Engineer,140000
Data Analytics Engineer,79866
Lead Data Analyst,170000
Data Analyst,80000
Data Scientist,45760
BI Data Analyst,100000
Data Scientist,53641
Head of Data,235000
BI Data Analyst,150000
Data Engineering Manager,79833
Machine Learning Scientist,225000
Data Science Consultant,77481
Machine Learning Infrastructure Engineer,50180
Marketing Data Analyst,89402
Lead Data Engineer,103750
Director of Data Engineering,114125
Machine Learning Engineer,95362
Data Engineer,30509
Data Engineer,150000
Data Engineer,115000
Research Scientist,187917
Data Analyst,51814
Data Engineer,106000
Data Engineer,112872
BI Data Analyst,36732
Data Engineer,150000
ML Engineer,15966
Computer Vision Software Engineer,96554
Computer Vision Software Engineer,70000
Financial Data Analyst,450000
Data Scientist,76958
Cloud Data Engineer,89514
Data Scientist,29831
Lead Data Engineer,276000
Data Engineer,188000
Cloud Data Engineer,160000
Data Scientist,105000
Data Engineer,200000
Data Engineering Manager,174000
Data Analyst,93000
Data Scientist,28475
Research Scientist,61270
Data Scientist,90000
Data Engineer,70139
Data Analyst,6072
Data Engineer,33511
Principal Data Analyst,170000
Data Engineer,96833
Data Engineer,13105
Data Scientist,36952
Data Engineer,72625
Data Analyst,91000
Big Data Architect,99956
Data Scientist,165000
Data Analyst,80000
Data Scientist,103954
Data Engineer,21695
Research Scientist,42000
Lead Data Scientist,115000
Research Scientist,63971
Machine Learning Scientist,260000
Head of Data Science,110000
Data Architect,180000
Data Analyst,200000
Big Data Engineer,109024
Director of Data Engineering,200000
ML Engineer,256000
Data Engineer,110000
Data Scientist,79833
Data Engineer,72500
Machine Learning Engineer,185000
Data Engineer,70329
Research Scientist,100000
Data Engineer,112000
Machine Learning Engineer,150000
Data Scientist,21843
AI Scientist,55000
Data Scientist,58000
Data Scientist,100000
Data Scientist,78340
Machine Learning Engineer,85000
Data Science Consultant,77481
Staff Data Scientist,105000
Data Analyst,72000
Data Engineer,65561
Data Engineer,30337
Data Engineer,111775
Data Engineer,93150
Lead Data Engineer,160000
Data Scientist,25747
Machine Learning Engineer,66442
Data Scientist,16949
Data Analyst,64369
Lead Data Scientist,190000
Director of Data Science,143043
Big Data Engineer,16271
Data Analyst,71968
Data Scientist,35735
Data Scientist,135000
Machine Learning Engineer,25032
Data Science Manager,54238
Machine Learning Engineer,24407
BI Data Analyst,9272
Data Scientist,147000
Research Scientist,96357
Data Science Manager,174000
Business Data Analyst,135000
Machine Learning Engineer,21844
Lead Data Engineer,125000
Data Scientist,51321
Data Scientist,40481
Data Science Consultant,70329
Data Analytics Engineer,50000
Data Engineer,4000
Data Scientist,39916
Lead Data Analyst,87000
Data Engineer,26224
Data Scientist,91500
Big Data Engineer,22671
Data Scientist,5695
Machine Learning Engineer,81000
Data Scientist,40798
Data Scientist,2876
Data Science Consultant,90000
Data Scientist,61985
Machine Learning Infrastructure Engineer,195000
Data Scientist,38144
Data Analyst,85000
Principal Data Scientist,416000
Machine Learning Scientist,225000
Data Scientist,56578
Data Scientist,33899
Data Scientist,117583
Machine Learning Engineer,47129
Data Analyst,8000
Data Engineer,41689
Big Data Engineer,114047
Machine Learning Engineer,89402
Data Science Consultant,5707
Lead Data Engineer,56000
Computer Vision Engineer,28850
Data Scientist,89402
Machine Learning Engineer,43331
Product Data Analyst,6072
Data Engineer,47899
BI Data Analyst,98000
Data Engineer,66400
Research Scientist,57217
Machine Learning Engineer,25032
Data Analytics Manager,120000
Data Engineer,20000
Director of Data Science,325000
Machine Learning Engineer,200000
AI Scientist,45896
Data Scientist,160000
Research Scientist,50000
Data Science Engineer,40529
Principal Data Engineer,600000
Data Scientist,13000
Data Engineer,165000
Big Data Engineer,5898
Data Scientist,42197
Principal Data Engineer,185000
Data Scientist,62726
Data Scientist,91500
Data Scientist,21669
Data Engineer,110000
Data Analytics Manager,140000
Data Scientist,120000
Data Scientist,87961
Finance Data Analyst,62250
Machine Learning Scientist,12000
Data Engineer,77481
Machine Learning Engineer,74000
Data Science Manager,152000
Big Data Engineer,18000
Computer Vision Engineer,60000
Data Scientist,130000
Computer Vision Engineer,19052
Business Data Analyst,59601
Principal Data Scientist,175228
Principal Data Scientist,148261
Data Scientist,38776
Data Scientist,47204
Data Scientist,4000
AI Scientist,18102
Data Scientist,91237
Data Scientist,62726
Data Scientist,115000
Principal Data Scientist,235000
Lead Data Analyst,19661
AI Scientist,12000
Data Analyst,75000
Data Analyst,62000
Data Scientist,73000
Data Engineer,45773
Data Science Manager,190200
Data Scientist,118000
Data Scientist,138350
Data Engineer,130800
Machine Learning Engineer,45618
Director of Data Science,168000
Data Scientist,119353
Applied Machine Learning Scientist,423000
Data Engineer,28608
Data Specialist,165000
Data Scientist,412000
Principal Data Scientist,151000
Data Scientist,105000
Business Data Analyst,100000
Data Science Manager,94917
您可以只使用原始 df
并使用 barplot
的 order
参数指定顺序。
可以通过对groupby.mean
的输出进行排序来确定order
:
order = df.groupby('job_title').mean().sort_values('salary_in_usd').index
然后将此 order
与 data=df
一起使用:
sns.barplot(
x='job_title',
y='salary_in_usd',
data=df,
order=order,
ci=None,
)
在将问题作为重复问题关闭之前,请完整阅读问题。
我正在尝试在 job_title
、salary_in_usd
列上绘制条形图。
我使用了以下代码:
job_salary = df[['job_title', 'salary_in_usd']]
job_salary = job_salary.sort_values(['salary_in_usd']).reset_index(drop=True)
fig = plt.figure(figsize=(14,12))
sns.barplot('job_title',
'salary_in_usd',
data=job_salary,
ci=None)
plt.xticks(rotation=90);
这是我得到的输出,它没有完全排序。
我知道Whosebug上已经有一个与此相关的问题。但这根本没有帮助。我尝试了该问题上发布的所有答案,但无济于事。
我正在处理以下数据集:https://www.kaggle.com/saurabhshahane/data-science-jobs-salaries
job_title,salary_in_usd
Data Science Consultant,64369
Data Scientist,68428
Head of Data Science,85000
Head of Data,230000
Machine Learning Engineer,125000
Data Analytics Manager,120000
Research Scientist,450000
Data Analyst,46759
Data Engineer,74130
Data Science Engineer,127543
Manager Data Science,144000
Data Scientist,13400
Data Scientist,75966
Data Scientist,150000
Data Science Consultant,103000
Data Engineering Manager,153000
Data Engineer,90000
Data Analyst,90000
Data Analyst,60000
Data Scientist,50000
AI Scientist,12000
3D Computer Vision Researcher,5423
ML Engineer,270000
Applied Data Scientist,54376
Machine Learning Engineer,47681
Director of Data Science,154963
Data Engineer,28801
Data Analytics Engineer,110000
Research Scientist,83000
Machine Learning Engineer,250000
Data Analyst,59601
Data Analyst,80000
Data Analyst,10000
Machine Learning Engineer,138000
Data Engineer,140000
Data Analytics Engineer,79866
Lead Data Analyst,170000
Data Analyst,80000
Data Scientist,45760
BI Data Analyst,100000
Data Scientist,53641
Head of Data,235000
BI Data Analyst,150000
Data Engineering Manager,79833
Machine Learning Scientist,225000
Data Science Consultant,77481
Machine Learning Infrastructure Engineer,50180
Marketing Data Analyst,89402
Lead Data Engineer,103750
Director of Data Engineering,114125
Machine Learning Engineer,95362
Data Engineer,30509
Data Engineer,150000
Data Engineer,115000
Research Scientist,187917
Data Analyst,51814
Data Engineer,106000
Data Engineer,112872
BI Data Analyst,36732
Data Engineer,150000
ML Engineer,15966
Computer Vision Software Engineer,96554
Computer Vision Software Engineer,70000
Financial Data Analyst,450000
Data Scientist,76958
Cloud Data Engineer,89514
Data Scientist,29831
Lead Data Engineer,276000
Data Engineer,188000
Cloud Data Engineer,160000
Data Scientist,105000
Data Engineer,200000
Data Engineering Manager,174000
Data Analyst,93000
Data Scientist,28475
Research Scientist,61270
Data Scientist,90000
Data Engineer,70139
Data Analyst,6072
Data Engineer,33511
Principal Data Analyst,170000
Data Engineer,96833
Data Engineer,13105
Data Scientist,36952
Data Engineer,72625
Data Analyst,91000
Big Data Architect,99956
Data Scientist,165000
Data Analyst,80000
Data Scientist,103954
Data Engineer,21695
Research Scientist,42000
Lead Data Scientist,115000
Research Scientist,63971
Machine Learning Scientist,260000
Head of Data Science,110000
Data Architect,180000
Data Analyst,200000
Big Data Engineer,109024
Director of Data Engineering,200000
ML Engineer,256000
Data Engineer,110000
Data Scientist,79833
Data Engineer,72500
Machine Learning Engineer,185000
Data Engineer,70329
Research Scientist,100000
Data Engineer,112000
Machine Learning Engineer,150000
Data Scientist,21843
AI Scientist,55000
Data Scientist,58000
Data Scientist,100000
Data Scientist,78340
Machine Learning Engineer,85000
Data Science Consultant,77481
Staff Data Scientist,105000
Data Analyst,72000
Data Engineer,65561
Data Engineer,30337
Data Engineer,111775
Data Engineer,93150
Lead Data Engineer,160000
Data Scientist,25747
Machine Learning Engineer,66442
Data Scientist,16949
Data Analyst,64369
Lead Data Scientist,190000
Director of Data Science,143043
Big Data Engineer,16271
Data Analyst,71968
Data Scientist,35735
Data Scientist,135000
Machine Learning Engineer,25032
Data Science Manager,54238
Machine Learning Engineer,24407
BI Data Analyst,9272
Data Scientist,147000
Research Scientist,96357
Data Science Manager,174000
Business Data Analyst,135000
Machine Learning Engineer,21844
Lead Data Engineer,125000
Data Scientist,51321
Data Scientist,40481
Data Science Consultant,70329
Data Analytics Engineer,50000
Data Engineer,4000
Data Scientist,39916
Lead Data Analyst,87000
Data Engineer,26224
Data Scientist,91500
Big Data Engineer,22671
Data Scientist,5695
Machine Learning Engineer,81000
Data Scientist,40798
Data Scientist,2876
Data Science Consultant,90000
Data Scientist,61985
Machine Learning Infrastructure Engineer,195000
Data Scientist,38144
Data Analyst,85000
Principal Data Scientist,416000
Machine Learning Scientist,225000
Data Scientist,56578
Data Scientist,33899
Data Scientist,117583
Machine Learning Engineer,47129
Data Analyst,8000
Data Engineer,41689
Big Data Engineer,114047
Machine Learning Engineer,89402
Data Science Consultant,5707
Lead Data Engineer,56000
Computer Vision Engineer,28850
Data Scientist,89402
Machine Learning Engineer,43331
Product Data Analyst,6072
Data Engineer,47899
BI Data Analyst,98000
Data Engineer,66400
Research Scientist,57217
Machine Learning Engineer,25032
Data Analytics Manager,120000
Data Engineer,20000
Director of Data Science,325000
Machine Learning Engineer,200000
AI Scientist,45896
Data Scientist,160000
Research Scientist,50000
Data Science Engineer,40529
Principal Data Engineer,600000
Data Scientist,13000
Data Engineer,165000
Big Data Engineer,5898
Data Scientist,42197
Principal Data Engineer,185000
Data Scientist,62726
Data Scientist,91500
Data Scientist,21669
Data Engineer,110000
Data Analytics Manager,140000
Data Scientist,120000
Data Scientist,87961
Finance Data Analyst,62250
Machine Learning Scientist,12000
Data Engineer,77481
Machine Learning Engineer,74000
Data Science Manager,152000
Big Data Engineer,18000
Computer Vision Engineer,60000
Data Scientist,130000
Computer Vision Engineer,19052
Business Data Analyst,59601
Principal Data Scientist,175228
Principal Data Scientist,148261
Data Scientist,38776
Data Scientist,47204
Data Scientist,4000
AI Scientist,18102
Data Scientist,91237
Data Scientist,62726
Data Scientist,115000
Principal Data Scientist,235000
Lead Data Analyst,19661
AI Scientist,12000
Data Analyst,75000
Data Analyst,62000
Data Scientist,73000
Data Engineer,45773
Data Science Manager,190200
Data Scientist,118000
Data Scientist,138350
Data Engineer,130800
Machine Learning Engineer,45618
Director of Data Science,168000
Data Scientist,119353
Applied Machine Learning Scientist,423000
Data Engineer,28608
Data Specialist,165000
Data Scientist,412000
Principal Data Scientist,151000
Data Scientist,105000
Business Data Analyst,100000
Data Science Manager,94917
您可以只使用原始 df
并使用 barplot
的 order
参数指定顺序。
可以通过对
groupby.mean
的输出进行排序来确定order
:order = df.groupby('job_title').mean().sort_values('salary_in_usd').index
然后将此
order
与data=df
一起使用:sns.barplot( x='job_title', y='salary_in_usd', data=df, order=order, ci=None, )