Plotly 中出现频率的直方图 Python

Histogram of the frequency of an occurrence in Plotly with Python

我想创建一个直方图,其中 y 值表示一个集合的出现次数,x 轴表示集合的数目。例如...

理想情况下,每组将关联三个条形(箱)。这是我想出的代码...

# Bins (x-axis)
bins = [1,2,3]

# Trace (y-axis)
passengers = [14, 27, 19]

# Data
data = [go.Histogram(x=bins, y=passengers)]

# Layout
layout = Layout(title='Histogram Example')      
    
# Figure
fig = {'data': data, 'layout': layout}

#Plot
iplot(fig)

使用 Plotly 的 go.Histogram 函数表示此数据的最简单方法是什么?

我使用官方参考资料使用您的数据创建了一个图表。参见 here

import plotly.graph_objects as go

bins = ["Age0-20","Age21-40","Age41-60"]
passengers = ["14","27","19"]

fig = go.Figure()

fig.add_trace(go.Histogram(histfunc="sum", y=passengers, x=bins, name="sum"))

fig.update_layout(showlegend=True)
fig.show()