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?
import
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,