【问题标题】:Plotly title is missing when combining 2 figures组合 2 个数字时缺少情节标题
【发布时间】:2021-02-26 03:17:54
【问题描述】:

当我使用 fig1.show() 时,我能够看到我的标题,但每当我将它与另一个情节结合时,标题就会丢失。感谢是否有人对此有解决方案。

import plotly.express as px
import plotly.graph_objects as go

fig1 = px.scatter(df, x='DateTime', y=["Variable"], title = 'Moving Average for Variable',color=y_colors)

fig2 = px.line(df x='DateTime', y=["SMA_3"])
fig2.update_traces(line=dict(color="Green"))
    
fig3 = go.Figure(data=fig1.data + fig2.data)
fig3.show

【问题讨论】:

    标签: python-3.x pandas plotly plotly-python


    【解决方案1】:

    您正在绘制 fig3,并且您的标题在 fig1 中。这是一个重新设计的建议,以便您可以同时更新具有相同格式的跟踪并将更改应用于全局图形。在我看来,在图中添加更多的痕迹也更容易。

    fig = go.Figure()
    
    trace1 = go.scatter(x=df['DateTime'], y=df["Variable"], color=y_colors)
    trace2 = go.line(x=df['DateTime'] y=df["SMA_3"], color='Green') 
    
    fig.add_trace(trace1)
    fig.add_trace(trace2)
    
    fig.update(layout_xaxis_rangeslider_visible=False)
    fig.update_layout(
    title = 'Moving Average for Variable',
    xaxis_title="My `enter code here`X axis",
    yaxis_title="My Y axis")
    fig.show()
    

    我没有你的数据,所以无法测试。但这就是我设置所有绘图图表的方式

    【讨论】:

    • 谢谢。我刚刚发现我可以在一个语句中做到这一点。
    【解决方案2】:

    发现我可以在一个语句中做到这一点

    fig3.update_layout(title='移动平均线')

    【讨论】:

      猜你喜欢
      • 2020-02-02
      • 2016-02-20
      • 1970-01-01
      • 2013-04-19
      • 2021-03-20
      • 2015-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多