[英]How to plot plotly gauge charts next to each other with python?
我的腳本中有兩個儀表圖,想並排顯示它們。
import plotly.graph_objects as go
fig1 = go.Figure(go.Indicator(mode="gauge+number", value=400, domain={'x': [0, 1], 'y': [0, 1]}, title={'text': "Speed 1"}))
fig2 = go.Figure(go.Indicator(mode="gauge+number", value=250, domain={'x': [0, 1], 'y': [0, 1]}, title={'text': "Speed 2"}))
如何並排顯示fig1
和fig2
?
您可以使用子圖並排顯示兩個圖。
import plotly.graph_objs as go
from plotly.subplots import make_subplots
trace1 = go.Indicator(mode="gauge+number", value=400, domain={'row' : 1, 'column' : 1}, title={'text': "Speed 1"})
trace2 = go.Indicator(mode="gauge+number", value=250, domain={'row' : 1, 'column' : 2}, title={'text': "Speed 2"})
fig = make_subplots(
rows=1,
cols=2,
specs=[[{'type' : 'indicator'}, {'type' : 'indicator'}]],
)
fig.append_trace(trace1, row=1, col=1)
fig.append_trace(trace2, row=1, col=2)
fig.show()
您使用domain
屬性走在正確的軌道上,但您的確切規范已關閉。 通過下面完整代碼中的其余設置,以下規范會生成相關的繪圖:
domain={'x': [0.0, 0.4], 'y': [0.0, 1]}
domain={'x': [0.6, 1.0], 'y': [0., 1.00]}
import plotly
import plotly.offline as py
import plotly.graph_objs as go
import plotly.express as px
# traces with separate domains to form a subplot
trace1 = go.Indicator(mode="gauge+number", value=400, domain={'x': [0.0, 0.4], 'y': [0.0, 1]}, title={'text': "Speed 1"})
trace2 = go.Indicator(mode="gauge+number", value=250, domain={'x': [0.6, 1.0], 'y': [0., 1.00]}, title={'text': "Speed 2"})
# layout and figure production
layout = go.Layout(height = 600,
width = 600,
autosize = False,
title = 'Side by side gauge diagrams')
fig = go.Figure(data = [trace1, trace2], layout = layout)
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.