Skip to content

Commit f5240eb

Browse files
committed
add scipy.stats to protected import
- add scipy.stats - edit examples in docstring
1 parent 8bb46eb commit f5240eb

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

plotly/tools.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def warning_on_one_line(message, category, filename, lineno,
5353

5454
try:
5555
import scipy
56-
from scipy.stats import norm, gaussian_kde
56+
import scipy.stats
5757
_scipy_imported = True
5858
except ImportError:
5959
_scipy_imported = False
@@ -2351,16 +2351,14 @@ def create_distplot(hist_data, group_labels,
23512351
import plotly.plotly as py
23522352
from plotly.tools import FigureFactory as FF
23532353
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]]
23542358
2359+
group_labels = ['distplot example']
23552360
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)
23642362
23652363
url = py.plot(fig, filename='Simple distplot', validate=False)
23662364
```
@@ -2379,7 +2377,7 @@ def create_distplot(hist_data, group_labels,
23792377
-0.3, 1.2, 0.56, 0.3, 2.2]
23802378
23812379
# Group data together
2382-
all_hist_data = [hist1_x] + [hist2_x]
2380+
hist_data = [hist1_x] + [hist2_x]
23832381
23842382
group_labels = ['2012', '2013']
23852383
@@ -2389,13 +2387,13 @@ def create_distplot(hist_data, group_labels,
23892387
23902388
# Create distplot
23912389
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)
23932391
23942392
# Add title
23952393
fig['layout'].update(title='Dist Plot')
23962394
23972395
# Plot!
2398-
py.iplot(fig, filename='Distplot with rug text', validate=False)
2396+
url = py.plot(fig, filename='Distplot with rug text', validate=False)
23992397
```
24002398
24012399
Example 3: Plot with normal curve and hide rug plot
@@ -2408,11 +2406,11 @@ def create_distplot(hist_data, group_labels,
24082406
x3 = np.random.randn(10)-1
24092407
x4 = np.random.randn(10)+2
24102408
2411-
all_hist_data = [x1] + [x2] + [x3] + [x4]
2409+
hist_data = [x1] + [x2] + [x3] + [x4]
24122410
group_labels = ['2012', '2013', '2014', '2015']
24132411
24142412
fig = FF.create_distplot(
2415-
all_hist_data, group_labels, curve_type='normal',
2413+
hist_data, group_labels, curve_type='normal',
24162414
show_rug=False, bin_size=.4)
24172415
24182416
url = py.plot(fig, filename='hist and normal curve', validate=False)
@@ -3139,7 +3137,8 @@ def make_kde(self):
31393137
self.curve_x[index] = [self.start[index] +
31403138
x * (self.end[index] - self.start[index])
31413139
/ 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])
31433142
(self.curve_x[index]))
31443143
self.curve_y[index] *= self.bin_size
31453144

@@ -3169,11 +3168,12 @@ def make_normal(self):
31693168
sd = [None]*self.trace_number
31703169

31713170
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]))
31733173
self.curve_x[index] = [self.start[index] +
31743174
x * (self.end[index] - self.start[index])
31753175
/ 500 for x in range(500)]
3176-
self.curve_y[index] = norm.pdf(
3176+
self.curve_y[index] = scipy.stats.norm.pdf(
31773177
self.curve_x[index], loc=mean[index], scale=sd[index])
31783178
self.curve_y[index] *= self.bin_size
31793179

0 commit comments

Comments
 (0)