'Hue in violin plot seaborn returns wrong values

I am having a problem with violin plot using seaborn. I am trying to visualize variable x (Liter/hectare) based on parameters y (Operation) and hue (soil_class). When I visualize violin plot using x and y, everything is fine (max x value is 6.9). But when I add category as a hue, it seem that it consider only values of hue, but not in relationship with y (it doesn't work like Group by y,hue).

The picture below shows an example of it. Vivid pink represents the violin plot when only one category (Operation) is considered (max x value is 6.9), and transcendent represents the plots when hue (soil_class) is added to plot, which obviously doesn't make sense, since rid group is located far from the max value, somewhere at 55.

enter image description here

When I've done descriptive statistics considering Operation (Y) and soil_class (hue) for the parameter Liter/hectare (X), the max value for Kontrola korova & rid was 6.90.

stats_fuel_ha_corr_groups = df_L_ha_corr_no_outliers.groupby(['Operation', 'soil_class'])['L_ha_corr'].describe().apply(lambda s: s.apply('{0:.2f}'.format))

enter image description here

When i've done descriptive statistics for Operation (Y) and paramter Liter/hectare (X), the max value was also 6.90.

stats_fuel_ha_corr_groups = df_L_ha_corr_no_outliers.groupby(['Operation'])['L_ha_corr'].describe().apply(lambda s: s.apply('{0:.2f}'.format))

enter image description here

But when I plot the graph above, soil_class rid is obviously sticking out with the value of around 55 L/ha. How is this possible? What am I doing wrong?

Code I use for violin plot:

##fig, ax = plt.subplots()
plt.figure(figsize=(10,40))
plt.xscale('log')
plt.xlim(0.1, 100)
p = sns.violinplot(x=df_L_ha_corr_no_outliers["L_ha_corr"], y=df_L_ha_corr_no_outliers["Operation"], 
                   hue=None, 
                   data=None,
                   order=None,
                   hue_order=None, 
                   bw='scott', 
                   cut=0, 
                   scale='count', 
                   scale_hue=True, 
                   gridsize=100, 
                   width=3, 
                   inner='box', 
                   split=False, 
                   dodge=True, 
                   orient=None, 
                   linewidth=None, 
                   color=None, 
             ##      palette="Reds", 
                   saturation=1, 
                   alpha  = 0.3,
                   ax=None)

graph2 = p.twinx()

r = sns.violinplot(x=df_L_ha_corr_no_outliers["L_ha_corr"], y=df_L_ha_corr_no_outliers["Operation"],  
                   hue=df_L_ha_corr_no_outliers["soil_class"], 
                   data=None,
                   order=None,
                   hue_order=None, 
                   bw='scott', 
                   cut=0, 
                   scale='count', 
                   scale_hue=True, 
                   gridsize=100, 
                   width=3, 
                   inner='box', 
                   split=False, 
                   dodge=True, 
                   orient=None, 
                   linewidth=None, 
                   color=None, 
                   palette="Paired", 
                   saturation=0.90, 
                   alpha=0.3,
                   ax=None)
r = plt.setp(r.collections, alpha=.3)

Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source