Python 如何在plotly中的单个页面中添加两个堆叠区域打印?

Python 如何在plotly中的单个页面中添加两个堆叠区域打印?,python,plotly,plotly-python,Python,Plotly,Plotly Python,因此,我为两种情况创建了堆叠面积图: 带存储 无存储 它们都是这样的: 带存储 无存储 但它们都在不同的页面上,我希望它们结合在一起。我编写这些图表的代码是: import plotly.graph_objs as go import plotly.offline as pyo from plotly.subplots import make_subplots import xlwings as xw import logging #Getting the Data app = xw.App(

因此,我为两种情况创建了堆叠面积图:

  • 带存储
  • 无存储 它们都是这样的:
  • 带存储

    无存储

    但它们都在不同的页面上,我希望它们结合在一起。我编写这些图表的代码是:

    import plotly.graph_objs as go
    import plotly.offline as pyo
    from plotly.subplots import make_subplots
    import xlwings as xw
    import logging
    
    #Getting the Data
    app = xw.App(visible=False)
    try:
        wb = app.books.open('PCM Fuel Wise Chart.xlsx')
        sheet = wb.sheets[0]
        dateWithStorage = sheet.range('A2:A8065').value
        coalWithStorage = sheet.range('D2:D8065').value
        nuclearWithStorage = sheet.range('E2:E8065').value
        gasWithStorage = sheet.range('F2:F8065').value
        bagasseWithStorage = sheet.range('G2:G8065').value
        hydroWithStorage = sheet.range('H2:H8065').value
        windWithStorage = sheet.range('I2:I8065').value
        solarWithStorage = sheet.range('J2:J8065').value
        bessCharging = sheet.range('L2:L8065').value
        bessDischarging = sheet.range('M2:M8065').value
        time = sheet.range('O2:O8065').value
    
        sheet = wb.sheets[1]
        dateWithoutStorage = sheet.range('A2:A8065').value
        coalWithoutStorage = sheet.range('D2:D8065').value
        nuclearWithoutStorage = sheet.range('E2:E8065').value
        gasWithoutStorage = sheet.range('F2:F8065').value
        bagasseWithoutStorage = sheet.range('G2:G8065').value
        hydroWithoutStorage = sheet.range('H2:H8065').value
        windWithoutStorage = sheet.range('I2:I8065').value
        solarWithoutStorage = sheet.range('J2:J8065').value
        time = sheet.range('O2:O8065').value
    except Exception as e:
        logging.exception("Something awful happened!")
        print(e)
    finally:
        app.quit()
        app.kill()
    
    #Plotting the Data
    trace1 = []
    trace1.append({'x': dateWithStorage,'y': coalWithoutStorage, 'name': 'Coal', 'mode':'lines', 'line' : dict(width = 0.5, color = 'grey'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': nuclearWithStorage, 'name': 'Nuclear', 'mode':'lines', 'line' : dict(width = 0.5, color = 'red'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': gasWithStorage, 'name': 'Gas', 'mode':'lines', 'line' : dict(width = 0.5, color = 'blue'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': bagasseWithStorage, 'name': 'Bagasse', 'mode':'lines', 'line' : dict(width = 0.5, color = 'purple'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': hydroWithStorage, 'name': 'Hydro', 'mode':'lines', 'line' : dict(width = 0.5, color = 'cyan'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': windWithStorage, 'name': 'Wind', 'mode':'lines', 'line' : dict(width = 0.5, color = 'green'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': solarWithStorage, 'name': 'Solar', 'mode':'lines', 'line' : dict(width = 0.5, color = 'yellow'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': bessCharging, 'name': 'BESS Charging', 'mode':'lines', 'line' : dict(width = 0.5, color = 'brown'), 'stackgroup': 'one'})
    trace1.append({'x': dateWithStorage,'y': bessDischarging, 'name': 'BESS Discharging', 'mode':'lines', 'line' : dict(width = 0.5, color = 'orange'), 'stackgroup': 'one'})
    
    fig = go.Figure({'data': trace1})
    pyo.plot(fig, filename= 'testing.html')
    
    我不知道如何将子地块和堆叠面积地块添加到一起,所以有人可以帮忙吗?
    我已经用这段代码创建了这些图,我只需要一种方法将这两个图集成到一个图中。

    您可以创建一个包含两行的子图,然后绘制该子图

    这可能是一个最小的例子

    导入plotly.graph\u objs as go
    将plotly.offline作为pyo导入
    从plotly.subplot导入make_子地块
    图=生成子图(行=2,列=1)
    #带存储的痕迹
    trace1=go.Scatter({'x':[3,3.1],'y':[1,1.1],'name':'Coal','mode':'lines','line':dict(宽度=0.5,颜色='grey'),'stackgroup':'one'})
    trace2=go.Scatter({'x':[4,4.2],'y':[2,2.1],'name':'Nuclear','mode':'lines','line':dict(宽度=0.5,颜色='red'),'stackgroup':'one'})
    #无储存痕迹
    trace3=go.Scatter({'x':[5,5.1],'y':[2,2.1],'name':'Coal','mode':'lines','line':dict(宽度=0.5,颜色='grey'),'stackgroup':'one'})
    trace4=go.Scatter({'x':[6,6.1],'y':[3,3.1],'name':'Nuclear','mode':'lines','line':dict(宽度=0.5,颜色='red'),'stackgroup':'one'))
    图=生成子图(行=2,列=1)
    #我们将每个跟踪添加到它们的子批次中
    图添加_轨迹(轨迹1,1,1)
    图添加轨迹(轨迹2,1,1)
    图添加轨迹(轨迹3,2,1)
    图1添加轨迹(轨迹4,2,1)
    图更新布局(高度=600,宽度=600,标题文本=“堆叠子地块”)
    plot(图,文件名='testing.html')