python 图中的某些数据不允许我查看其他数据

14ifxucb  于 2023-03-21  发布在  Python
关注(0)|答案(1)|浏览(83)

所以我在一个 Dataframe 上有大量的数据,我想可视化它。

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(6, 6))

colors = {'Sunny':'tab:blue', 'Hurricane':'tab:orange', 'Cloudy':'tab:green', 'Rain':'tab:red', 'Foggy':'tab:purple', 'Storm':'tab:brown'}

grouped = df.groupby('Climate')
for key, group in grouped:
    group.plot(ax=ax, kind='scatter', x='month', y='eta/km*100', label=key, color=colors[key])
    plt.xticks(range(1, 13))
plt.show()

问题是它看起来像这样:

正如你所看到的,多云,有雾和下雨不能被看到,因为有一些数据在他们面前。我可以尝试迫使他们显示在前面,但其他气候不会被看到。
什么是最好的解决方案呢?我不知道是否有可能移动每种类型的天气一些像素的X轴,以便能够看到所有的数据,但仍然有他们在同一个月或类似的东西,谢谢!

chhqkbe1

chhqkbe11#

正如@mozway所说,解决方案是使用stripplot
我实现的代码:

import seaborn as sns
sns.stripplot(data=df, x="month", y="eta/km*100", palette="deep", hue="Climate", dodge="True")

情节:

相关问题