3
votes

I am using pandas groupby for plotting wind speed Vs direction using a bar and whisker plot. However the xaxis is not readable due to so many wind direction value close to each other.

I have tried the oc_params ax.set_xticks but instead I am having empty x-axis or modified xaxis with different values

The head of my dataframe

    Kvit_TIU     dir_cat  
0   0.064740         14  
1   0.057442         15  
2   0.056750         15  
3   0.069002         17  
4   0.068464         17  
5   0.067057         17  
6   0.071901         12  
7   0.050464          5  
8   0.066165          1  
9   0.073993         27  
10  0.090784         34  
11  0.121366         33  
12  0.087172         34  
13  0.066197         30  
14  0.073020         17  
15  0.071784         16  
16  0.081699         17  
17  0.088014         14  
18  0.076758         14  
19  0.078574         14  

I used groupby = dir_cat to create a box plot

fig = plt.figure() # create the canvas for plotting
ax1 = plt.subplot(1,1,1) 
ax1 = df_KvTr10hz.boxplot(column='Kvit_TIU', by='dir_cat', showfliers=False, showmeans=True)
ax1.set_xticks([30,90, 180,270, 330])

I would like to have the x-axis plotted with a reduced frequency. So that the plot can be readable unreadable plotusing ax1.set_xticks

enter image description here

enter image description here

1
Kvit_TIU dir_cat 0 0.064740 14 1 0.057442 14 2 0.056750 15 3 0.069002 15 4 0.068464 17 - Zak

1 Answers

0
votes
 ax1 = df_KvTr10hz.dropna().boxplot(column='Kvit_TIU', by='dir_cat', showfliers=False, showmeans=True)

EDIT: Using OP sample dataframe

sample

However, if we substitute with NaNs the Kvit_TIU values for 'dir_cat'>=30

samplewithNaN