在 create_distplot Python 中使用计数

Use count in create_distplot Python

我想使用计数作为 y 轴而不是密度作为百分比,如下面的代码所示:

import plotly.figure_factory as ff
import numpy as np

# Add histogram data
x1 = np.random.randn(200) - 2
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 2
x4 = np.random.randn(200) + 4

# Group data together
hist_data = [x1, x2, x3, x4]

group_labels = ['Group 1', 'Group 2', 'Group 3', 'Group 4']

# Create distplot with custom bin_size
fig = ff.create_distplot(hist_data, group_labels, bin_size=.2)
fig.show()

我尝试添加参数 histnorm= '',它确实将 y 轴更改为计数:

import plotly.figure_factory as ff
import numpy as np
fig = go.Figure()
# Add histogram data
x1 = np.random.randn(200) - 2
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 2
x4 = np.random.randn(200) + 4

# Group data together
hist_data = [x1, x2, x3, x4]

group_labels = ['Group 1', 'Group 2', 'Group 3', 'Group 4']

# Create distplot with custom bin_size
fig = ff.create_distplot(hist_data, group_labels, bin_size=.2, histnorm= '')
fig.show()

但是它删除了折线图:

有没有办法在不改变图表的其他部分(例如折线图)的情况下更改 y 轴以进行计数?

再次查看 hist='' 输出,我注意到 kde 曲线没有被删除,它只是由于 y-axis 值增加而被拉直和删除。所以通过改变图形大小的高度,可以看到曲线。

import plotly.figure_factory as ff
import numpy as np

# Add histogram data
x1 = np.random.randn(200) - 2
x2 = np.random.randn(200)
x3 = np.random.randn(200) + 2
x4 = np.random.randn(200) + 4

# Group data together
hist_data = [x1, x2, x3, x4]

group_labels = ['Group 1', 'Group 2', 'Group 3', 'Group 4']

# Create distplot with custom bin_size
fig = ff.create_distplot(hist_data, group_labels, bin_size=.2, histnorm='')
fig.update_layout(autosize=False, height=800)# update

fig.show()