[英]Fix the scale/size of the y axis
我正在使用 Plotly 為我正在構建的網站顯示一些圖表。
用戶可以回答一些問題,圖形顯示“已回答的問題/未回答的問題”的百分比。
我同時使用條形圖和雷達圖來直觀地顯示這樣的百分比。 (這個百分比的范圍從 0 到 1)。
但是,y 軸從不固定為從 0 到 1 的刻度,而是從 0 到回答的最高百分比。
例如:
如果用戶回答了 70% 的問題,則 y 軸顯示最大值為 0.7 (70%) 而不是 1 (100%)。
我希望 y 軸比例始終為 1 (100%),而不是根據用戶的回答進行調整。
雷達圖也會出現這種情況。
我的代碼:
fig2 = go.Figure()
fig2.add_trace(go.Bar(
x=categories,
y=[a1, b1, c1, d1, e1],
name='You',
marker_color='#A5A9F7'
))
fig2.add_trace(go.Bar(
x=categories,
y=[a2, b2, c2, d2, e2],
name='Other',
marker_color='#E89C8C'
))
fig2.update_layout(
title=go.layout.Title(
text="<b>This graph show the percentage (0 to 1)",
font=dict(size=10),
xref="paper",
x=0
)
)
對於條形圖,您可以添加:
yaxis=dict( range=[0, 1] )
這里:
fig2 = go.Figure()
fig2.add_trace(go.Bar(
x=categories,
y=[a1, b1, c1, d1, e1],
name='You',
marker_color='#A5A9F7'
))
fig2.add_trace(go.Bar(
x=categories,
y=[a2, b2, c2, d2, e2],
name='Other',
marker_color='#E89C8C'
))
fig2.update_layout(
title=go.layout.Title(
text="<b>This graph show the percentage (0 to 1)",
font=dict(size=10),
xref="paper",
x=0
),
yaxis=dict( # Here
range=[0, 1] # Here
) # Here
)
對於雷達圖,您可以添加:
range = [0, 1]
就像是:
layout = go.Layout(
polar = dict(
radialaxis = dict(
visible = True,
range = [0, 50]
)
),
showlegend = False
)
如果要在 Y 軸上設置限制,請使用:
plt.ylim(0,1)
編輯,情節這應該這樣做:
fig2.update_yaxes(range=[0, 1])
文檔: https : //plot.ly/python/axes/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.