简体   繁体   English

在 create_distplot 中使用计数 Python

[英]Use count in create_distplot Python

I would like to use count as the y-axis instead of density as a percentage, as shown in the plot with code below:我想使用计数作为 y 轴而不是密度作为百分比,如 plot 所示,代码如下:

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()

在此处输入图像描述

I tried adding the argument histnorm= '' , which did change y-axis to count:我尝试添加参数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()

However it had the line chart removed:但是它删除了折线图: 在此处输入图像描述

Is there a way to change the y-axis to count without altering the other parts of the plot, eg., the line chart?有没有办法在不改变 plot 的其他部分(例如折线图)的情况下更改 y 轴以进行计数?

Looking at the hist='' output again, I noticed that the kde curve is not deleted, it just appears to be straightened and deleted due to the increased y-axis value.再次查看hist='' output,我注意到 kde 曲线没有被删除,它只是由于 y 轴值的增加而被拉直和删除。 So by changing the height of the graph size, the curve can be seen.所以通过改变图形大小的高度,就可以看到曲线了。

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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM