@@ -53,7 +53,7 @@ def warning_on_one_line(message, category, filename, lineno,
53
53
54
54
try :
55
55
import scipy
56
- from scipy .stats import norm , gaussian_kde
56
+ import scipy .stats
57
57
_scipy_imported = True
58
58
except ImportError :
59
59
_scipy_imported = False
@@ -2351,16 +2351,14 @@ def create_distplot(hist_data, group_labels,
2351
2351
import plotly.plotly as py
2352
2352
from plotly.tools import FigureFactory as FF
2353
2353
2354
+ hist_data = [[1.1, 1.1, 2.5, 3.0, 3.5,
2355
+ 3.5, 4.1, 4.4, 4.5, 4.5,
2356
+ 5.0, 5.0, 5.2, 5.5, 5.5,
2357
+ 5.5, 5.5, 5.5, 6.1, 7.0]]
2354
2358
2359
+ group_labels = ['distplot example']
2355
2360
2356
- hist_x = [[1.1, 1.1, 2.5, 3.0, 3.5,
2357
- 3.5, 4.1, 4.4, 4.5, 4.5,
2358
- 5.0, 5.0, 5.2, 5.5, 5.5,
2359
- 5.5, 5.5, 5.5, 6.1, 7.0]]
2360
-
2361
- group_label = ['distplot example']
2362
-
2363
- fig = FF.create_distplot(hist_x, group_label)
2361
+ fig = FF.create_distplot(hist_data, group_labels)
2364
2362
2365
2363
url = py.plot(fig, filename='Simple distplot', validate=False)
2366
2364
```
@@ -2379,7 +2377,7 @@ def create_distplot(hist_data, group_labels,
2379
2377
-0.3, 1.2, 0.56, 0.3, 2.2]
2380
2378
2381
2379
# Group data together
2382
- all_hist_data = [hist1_x] + [hist2_x]
2380
+ hist_data = [hist1_x] + [hist2_x]
2383
2381
2384
2382
group_labels = ['2012', '2013']
2385
2383
@@ -2389,13 +2387,13 @@ def create_distplot(hist_data, group_labels,
2389
2387
2390
2388
# Create distplot
2391
2389
fig = FF.create_distplot(
2392
- all_hist_data , group_labels, rug_text=rug_text, bin_size=.2)
2390
+ hist_data , group_labels, rug_text=rug_text, bin_size=.2)
2393
2391
2394
2392
# Add title
2395
2393
fig['layout'].update(title='Dist Plot')
2396
2394
2397
2395
# Plot!
2398
- py.iplot (fig, filename='Distplot with rug text', validate=False)
2396
+ url = py.plot (fig, filename='Distplot with rug text', validate=False)
2399
2397
```
2400
2398
2401
2399
Example 3: Plot with normal curve and hide rug plot
@@ -2408,11 +2406,11 @@ def create_distplot(hist_data, group_labels,
2408
2406
x3 = np.random.randn(10)-1
2409
2407
x4 = np.random.randn(10)+2
2410
2408
2411
- all_hist_data = [x1] + [x2] + [x3] + [x4]
2409
+ hist_data = [x1] + [x2] + [x3] + [x4]
2412
2410
group_labels = ['2012', '2013', '2014', '2015']
2413
2411
2414
2412
fig = FF.create_distplot(
2415
- all_hist_data , group_labels, curve_type='normal',
2413
+ hist_data , group_labels, curve_type='normal',
2416
2414
show_rug=False, bin_size=.4)
2417
2415
2418
2416
url = py.plot(fig, filename='hist and normal curve', validate=False)
@@ -3139,7 +3137,8 @@ def make_kde(self):
3139
3137
self .curve_x [index ] = [self .start [index ] +
3140
3138
x * (self .end [index ] - self .start [index ])
3141
3139
/ 500 for x in range (500 )]
3142
- self .curve_y [index ] = (gaussian_kde (self .hist_data [index ])
3140
+ self .curve_y [index ] = (scipy .stats .gaussian_kde
3141
+ (self .hist_data [index ])
3143
3142
(self .curve_x [index ]))
3144
3143
self .curve_y [index ] *= self .bin_size
3145
3144
@@ -3169,11 +3168,12 @@ def make_normal(self):
3169
3168
sd = [None ]* self .trace_number
3170
3169
3171
3170
for index in range (self .trace_number ):
3172
- mean [index ], sd [index ] = norm .fit (self .hist_data [index ])
3171
+ mean [index ], sd [index ] = (scipy .stats .norm .fit
3172
+ (self .hist_data [index ]))
3173
3173
self .curve_x [index ] = [self .start [index ] +
3174
3174
x * (self .end [index ] - self .start [index ])
3175
3175
/ 500 for x in range (500 )]
3176
- self .curve_y [index ] = norm .pdf (
3176
+ self .curve_y [index ] = scipy . stats . norm .pdf (
3177
3177
self .curve_x [index ], loc = mean [index ], scale = sd [index ])
3178
3178
self .curve_y [index ] *= self .bin_size
3179
3179
0 commit comments