close

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

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to overlay two plots in same figure in plotly ( Create Pareto chart in plotly ) in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

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

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

    You can do something like so:
    fig = make_subplots(rows=1, cols=2) fig.add_trace(trace1, row=1, col=1) fig.add_trace(trace2, row=1, col=2)

  2. overlay two plots in same figure in plotly ( Create Pareto chart in plotly )

    You can do something like so:
    fig = make_subplots(rows=1, cols=2) fig.add_trace(trace1, row=1, col=1) fig.add_trace(trace2, row=1, col=2)

Method 1

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, 

Method 2

You can do something like so:

fig = make_subplots(rows=1, cols=2)
fig.add_trace(trace1, row=1, col=1)
fig.add_trace(trace2, row=1, col=2)

fig.update_layout(xaxis=dict(tickangle=90))
fig.show()

Which will produce the following graph: 

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read