✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

How to use Plotly express to create multiple charts in the same figure(I need 3 charts in one figure--one stacked bar chart and two lines)

Hello there,

I am trying to plot multiple charts in one graph using plotly express. I need to plot one stacked bar chart and two lines in the same figure. I have 5 columns–year,priority,value,opened and closed. I was able to plot stacked bar chart as shown in the code pasted below. Can anyone help me in plotting two more lines–one with ‘opened’ column w.r.t ‘year’ and other with ‘closed’ w.r.t ‘year’. Looking forward for your help. Thanks in advance.
Tried with add_trace() but did not work. plotly graph objects is not working in my notebook version as it is showing blank. So plotly express is my only way out now.
Code to plot stacked bar chart(Please help for drawing two more lines in the same graph):
import plotly_express as px
fig = px.bar(df, x=‘year’, y=‘value’,color=‘priority’,
hover_data=[‘priority’, ‘value’],
labels={‘value’:‘priority’}, height=400)


1 Like

Hello Sameerass! Welcome to to forum! If I understand your question correctly I believe you are looking for the make subplots function. This function can be used to create a grid like layout of graphs! Also if you are looking to have subplots with multiple y or x axes this example should help you accomplish that!

Good luck with your project and feel free to post again if you need any more help!

hi, same question here…

The above-mentioned subplots solution will work for self-analysis, but for certain scenarios (e.g. presentation purpose), it would be nice to have multiple chart types to fit in one single figure, just like the example here made by graph_objects - https://plot.ly/python/graphing-multiple-chart-types/

Is it possible that we achieve the same by using plotly express? Thanks in advance


@Krichardson Thank you for responding. I am not looking for subplots in the same figure. I want all the figures–scatter and bar to be merged in the same trace. I could figure out a way using something like this
Thanks much!

You have no closing sqaure bracket for this solution.