[英]Histogram of the frequency of an occurrence in Plotly with Python
I would like to create a histogram with the y values representing the number of occurrences of a set and the x axis representing the number of sets.我想创建一个直方图,y 值表示集合的出现次数,x 轴表示集合的数量。 For example...例如...
Ideally, there would be three bars (bins) associated with each set.理想情况下,每组将有三个条(箱)。 Here is the code I've come up with...这是我想出的代码......
# 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)
What is the simplest way to represent this data with Plotly's go.Histogram function?用 Plotly 的 go.Histogram 函数表示这些数据的最简单方法是什么?
I have created a graph using your data using the official reference.我使用官方参考资料使用您的数据创建了一个图表。 See 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.