我使用matplotlib.pyplot和seaborn库创建了一个条形图。如何根据Speed
按升序排列条形图?我想看看左侧最低速度和右侧最高速度的酒吧。如何按升序对条形图中的条形进行排序?
df =
Id Speed
1 30
1 35
1 31
2 20
2 25
3 80
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
result = df.groupby(["Id"])['Speed'].aggregate(np.median).reset_index()
norm = plt.Normalize(df["Speed"].values.min(), df["Speed"].values.max())
colors = plt.cm.Reds(norm(df["Speed"]))
plt.figure(figsize=(12,8))
sns.barplot(x="Id", y="Speed", data=gr_vel_1, palette=colors)
plt.ylabel('Speed', fontsize=12)
plt.xlabel('Id', fontsize=12)
plt.xticks(rotation='vertical')
plt.show()
回答更新。 –