Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b28b4a2

Browse files
committed
added histnorm parameter
1 parent 1245b10 commit b28b4a2

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

plotly/tools.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4019,7 +4019,7 @@ def create_candlestick(open, high, low, close,
40194019
@staticmethod
40204020
def create_distplot(hist_data, group_labels,
40214021
bin_size=1., curve_type='kde',
4022-
colors=[], rug_text=[],
4022+
colors=[], rug_text=[], histnorm='probability density',
40234023
show_hist=True, show_curve=True,
40244024
show_rug=True):
40254025
"""
@@ -4144,23 +4144,23 @@ def create_distplot(hist_data, group_labels,
41444144
bin_size = [bin_size]*len(hist_data)
41454145

41464146
hist = _Distplot(
4147-
hist_data, group_labels, bin_size,
4147+
hist_data, histnorm, group_labels, bin_size,
41484148
curve_type, colors, rug_text,
41494149
show_hist, show_curve).make_hist()
41504150

41514151
if curve_type == 'normal':
41524152
curve = _Distplot(
4153-
hist_data, group_labels, bin_size,
4153+
hist_data, histnorm, group_labels, bin_size,
41544154
curve_type, colors, rug_text,
41554155
show_hist, show_curve).make_normal()
41564156
else:
41574157
curve = _Distplot(
4158-
hist_data, group_labels, bin_size,
4158+
hist_data, histnorm, group_labels, bin_size,
41594159
curve_type, colors, rug_text,
41604160
show_hist, show_curve).make_kde()
41614161

41624162
rug = _Distplot(
4163-
hist_data, group_labels, bin_size,
4163+
hist_data, histnorm, group_labels, bin_size,
41644164
curve_type, colors, rug_text,
41654165
show_hist, show_curve).make_rug()
41664166

@@ -5036,10 +5036,11 @@ class _Distplot(FigureFactory):
50365036
"""
50375037
Refer to TraceFactory.create_distplot() for docstring
50385038
"""
5039-
def __init__(self, hist_data, group_labels,
5039+
def __init__(self, hist_data, histnorm, group_labels,
50405040
bin_size, curve_type, colors,
50415041
rug_text, show_hist, show_curve):
50425042
self.hist_data = hist_data
5043+
self.histnorm = histnorm
50435044
self.group_labels = group_labels
50445045
self.bin_size = bin_size
50455046
self.show_hist = show_hist
@@ -5081,7 +5082,7 @@ def make_hist(self):
50815082
x=self.hist_data[index],
50825083
xaxis='x1',
50835084
yaxis='y1',
5084-
histnorm='probability density',
5085+
histnorm=self.histnorm,
50855086
name=self.group_labels[index],
50865087
legendgroup=self.group_labels[index],
50875088
marker=dict(color=self.colors[index]),
@@ -5108,7 +5109,9 @@ def make_kde(self):
51085109
self.curve_y[index] = (scipy.stats.gaussian_kde
51095110
(self.hist_data[index])
51105111
(self.curve_x[index]))
5111-
# self.curve_y[index] *= self.bin_size[index]
5112+
5113+
if self.histnorm == 'probability':
5114+
self.curve_y[index] *= self.bin_size[index]
51125115

51135116
for index in range(self.trace_number):
51145117
curve[index] = dict(type='scatter',
@@ -5143,7 +5146,9 @@ def make_normal(self):
51435146
/ 500 for x in range(500)]
51445147
self.curve_y[index] = scipy.stats.norm.pdf(
51455148
self.curve_x[index], loc=mean[index], scale=sd[index])
5146-
# self.curve_y[index] *= self.bin_size[index]
5149+
5150+
if self.histnorm == 'probability':
5151+
self.curve_y[index] *= self.bin_size[index]
51475152

51485153
for index in range(self.trace_number):
51495154
curve[index] = dict(type='scatter',
@@ -5621,4 +5626,3 @@ def make_table_annotations(self):
56215626
font=dict(color=font_color),
56225627
showarrow=False))
56235628
return annotations
5624-

0 commit comments

Comments
 (0)