0

So I have a huge amount of data on a dataframe and I want to visualize it. This is the code I use to create the plot, extracted from here

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()

The issue is that it looks like this:

enter image description here

As you can see, cloudy, foggy and rain cant be seen because there is some data in front of them. I could try to force them to show in front but then other climate wont be seen.

What's the best solution to this? I dont know if it's possible to move each type of weather some pixels on the X axys to be able to see all of the data but still have them on the same month or something like that, thanks!

Alberto
  • 91
  • 7
  • 1
    I'm guessing this will depend on the order of the plotting functions. So plot the highest value first, then subsequently lower values. The latter will be overplotted, while the higher values will stick out at the top. You can do that manually, or try and program some logic by looking at the data values, sorting them by e.g. maximum value for each group. – 9769953 Mar 21 '23 at 11:07
  • 2
    Use a [`stripplot`](https://seaborn.pydata.org/generated/seaborn.stripplot.html#seaborn.stripplot) with `dodge=True`? – mozway Mar 21 '23 at 11:10
  • 2
    Apart from using a stripplot, you can further try to use smaller dots and transparency. – JohanC Mar 21 '23 at 11:13
  • 1
    @mozway That was the solution, thanks again! – Alberto Mar 21 '23 at 11:16

1 Answers1

0

As @mozway said, the solution was using stripplot

The code I implemented:

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

The plot:

enter image description here

Alberto
  • 91
  • 7