微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python-如何使用python绘制绘图仪表图? 域名规范情节完整代码

如何解决python-如何使用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,title={'text': "Speed 2"}))

如何显示fig1fig2并排显示

解决方法

使用domain属性可以使您处于正确的轨道,但是您的确切规格不正确。对于下面完整代码中的其余设置,以下规范将产生关联的图:

域名规范

 domain={'x': [0.0,0.4],'y': [0.0,1]}

 domain={'x': [0.6,1.0],'y': [0.,1.00]}

情节

enter image description here

完整代码

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,1]},title={'text': "Speed 1"})

trace2 = go.Indicator(mode="gauge+number",value=250,domain={'x': [0.6,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()
,

您可以使用子图同时显示两个图形。

import plotly.graph_objs as go
from plotly.subplots import make_subplots

trace1 = go.Indicator(mode="gauge+number",domain={'row' : 1,'column' : 1},title={'text': "Speed 1"})
trace2 = go.Indicator(mode="gauge+number",'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,col=2)

fig.show()

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。