1

I am trying to visualize some stats of features, and some of my features have value 0, and i am using seaborn histplot's parameter log_scale which takes log for base 10 and because i have 0 present in my feature values, i can not visualize the plot, so what should i do without doing harm to data ?

my code:

fig, axes = plt.subplots(ncols=2, nrows=len(METAFEATURES), figsize=(20,50),dpi=100)

for i, feature in enumerate(METAFEATURES):
    sns.histplot(dfs['toxic'][feature], label='toxic', ax=axes[i][0], color=colors[0],log_scale=True)
    sns.histplot(dfs['severe_toxic'][feature], label='severe_toxic',ax=axes[i][0], color=colors[1],log_scale=True)
    sns.histplot(dfs['obscene'][feature], label='obscene', ax=axes[i][0], color=colors[2],log_scale=True)
    sns.histplot(dfs['threat'][feature], label='threat', ax=axes[i][0], color=colors[3],log_scale=True)
    sns.histplot(dfs['insult'][feature], label='insult', ax=axes[i][0], color=colors[4],log_scale=True)
    sns.histplot(dfs['identity_hate'][feature], label='identity_hate', ax=axes[i][0], color=colors[5],log_scale=True)
    
    sns.histplot(train_df[feature], label="Training", ax=axes[i][1],color=colors[0],log_scale=True)
    sns.histplot(test_df[feature], label='Test', ax=axes[i][1],color=colors[1],log_scale=True)
    
    for j in range(2):
        axes[i][j].set_xlabel('')
        axes[i][j].tick_params(axis='x', labelsize=12)
        axes[i][j].tick_params(axis='y', labelsize=12)
        axes[i][j].legend()
        
    axes[i][0].set_title(f"{feature} Target Distribution in Training Set", fontsize=13)
    axes[i][1].set_title(f"{feature} Training & Test Set Distribution", fontsize=13)
    
plt.show()
Sudhanshu
  • 704
  • 1
  • 9
  • 24
  • 3
    This is not an MCVE. But maybe changing the axis to [symlog](https://matplotlib.org/stable/gallery/scales/symlog_demo.html) might be of help. – Mr. T May 21 '21 at 17:56
  • 1
    Instead of `log_scale=True` you could manually calculate some suitable bin boundaries (automatic is cumbersome as `log(0)` is minus infinity). And afterwards set a semilog or symlog scale to the x-axis. – JohanC May 22 '21 at 16:01

0 Answers0