[英]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 函數表示這些數據的最簡單方法是什么?
我使用官方參考資料使用您的數據創建了一個圖表。 見這里。
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.