In [9]:
from sklearn.preprocessing import StandardScaler
import numpy as np
import seaborn as sns
import scipy.stats as stats
import spacepy.toolbox as tb
import matplotlib.pyplot as plt

sns.set(font_scale=1.5)
%matplotlib inline

In [13]:
np.random.seed(123)
data = np.random.normal(10, 3.4, size=100)

In [14]:
sns.distplot(data)


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x11931a748>

In [17]:
h, b = np.histogram(data, bins=7)
b = tb.bin_edges_to_center(b)
plt.plot(b, h)


Out[17]:
[<matplotlib.lines.Line2D at 0x119354048>]

In [23]:
d = np.vstack((b,h)).T

In [24]:
scaler = StandardScaler()
print(scaler.fit(d))


StandardScaler(copy=True, with_mean=True, with_std=True)

In [33]:
scaler.mean_


Out[33]:
array([ 9.30941947, 14.28571429])

In [34]:
scaler.scale_


Out[34]:
array([5.04264139, 7.51596939])

In [38]:
trans = scaler.transform(d)
plt.plot(trans[:,0], trans[:,1])
plt.plot(b, h)


Out[38]:
[<matplotlib.lines.Line2D at 0x119c866a0>]

In [39]:
scaler.inverse_transform(trans)


Out[39]:
array([[ 1.74545739,  3.        ],
       [ 4.26677808,  7.        ],
       [ 6.78809878, 26.        ],
       [ 9.30941947, 19.        ],
       [11.83074017, 18.        ],
       [14.35206086, 18.        ],
       [16.87338156,  9.        ]])

In [42]:
plt.plot(trans[:,0], trans[:,1])
plt.plot(b, h)
plt.plot(scaler.inverse_transform(trans)[:,0], scaler.inverse_transform(trans)[:,1]+0.4)


Out[42]:
[<matplotlib.lines.Line2D at 0x1198daa20>]

In [ ]: