0

The following lines of code gives the plot but that is skewed towards left.

sns.distplot(fraud_false['Amount'],
             hist=False, color='darkblue',
             kde_kws = {'shade': True, 'linewidth': 3})

sns.distplot(fraud_true['Amount'],
             hist=False, color='darkred',
             kde_kws = {'shade': True, 'linewidth': 3})

plt.title('Density Plot')
plt.xlabel('Amount')
plt.ylabel('Density')

Taking log of data makes the distribution normal. But how to take the original values of data in x axis of the plot instead of these new log values?

Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52
Gourav Aggarwal
  • 49
  • 3
  • 10
  • How do readers run your code without having the complete data? Since you are new to Stack Overflow, take some time in reading [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Sheldore Feb 13 '20 at 14:31
  • Do I understand correctly that you want to keep the data log-transformed but on the x-axis of your distplot you want to have xticks that are not on log-transformed scale? – sim Feb 13 '20 at 14:34
  • @Sheldore sure sir. – Gourav Aggarwal Feb 13 '20 at 14:44
  • Yes, I am talking of the same @sim – Gourav Aggarwal Feb 13 '20 at 14:45
  • Also see [this post](https://stackoverflow.com/a/60132262/12046409) about how one could create log tick-labels for log-transformed data. – JohanC Feb 13 '20 at 16:22

1 Answers1

3

I hope I understand your question correctly:

You could either log-scale your entire axis. This will result in your bins in the distplot to also be log-scaled. Alternatively, you can log-transform your data and update your xticks to reflect the log-scale nature of your axis. Below shows this by example.

from scipy.stats import skewnorm
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sbs

fig, ax = plt.subplots(1, 3, figsize=(10, 5))
data = skewnorm.rvs(size=1000, a=5)
sbs.distplot(data, ax=ax[0])
sbs.distplot(data, ax=ax[1])
ax[1].set_xscale("log")
sbs.distplot(np.log(data), ax=ax[2])
ax[2].set_xticklabels([round(d, 1) for d in np.exp(ax[2].get_xticks())]);

enter image description here

sim
  • 1,227
  • 14
  • 20