How to overlay two plots in same figure in plotly ( Create Pareto chart in plotly )?

后端 未结 3 856
耶瑟儿~
耶瑟儿~ 2021-02-14 19:01

I was trying to plot barplot and scatterplot in the same plot in plotly, but it shows only scatterplot.

How to show both the plots?

data

import         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 19:48

    Try this:

    import plotly.graph_objects as go
    from plotly.subplots import make_subplots
    
    trace1 = go.Bar(
        x=df[cat],
        y=df[num],
        name=num,
        marker=dict(
            color='rgb(34,163,192)'
                   )
    )
    trace2 = go.Scatter(
        x=df[cat],
        y=df['cumulative_perc'],
        name='Cumulative Percentage',
        yaxis='y2'
    
    )
    
    fig = make_subplots(specs=[[{"secondary_y": True}]])
    fig.add_trace(trace1)
    fig.add_trace(trace2,secondary_y=True)
    fig['layout'].update(height = 600, width = 800, title = title,xaxis=dict(
          tickangle=-90
        ))
    iplot(fig)
    

    Gives,

提交回复
热议问题