I think you can use facet
options or use subplot
. Based on your data in your old post, I did something as below:
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
df = pd.read_csv('Car brand.csv')
df2 = pd.pivot_table(df,values='Model', index=['Brand','RapidCharge'], aggfunc='count').reset_index()
fig = px.bar(df2, x="Brand", y="Model", facet_row="RapidCharge", color='RapidCharge')
fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
fig.show()
or with subplot:
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df = pd.read_csv('Car brand.csv')
df2 = pd.pivot_table(df,values='Model', index=['Brand','RapidCharge'], aggfunc='count').reset_index()
df2_1 = df2[df2['RapidCharge'] == 'Rapid charging possible']
df2_2 = df2[df2['RapidCharge'] == 'Rapid charging not possible']
fig = make_subplots(
rows=1, cols=2,
subplot_titles=("Plot 1", "Plot 2"))
fig.add_trace(go.Bar(x=df2_1['Brand'], y=df2_1['Model']),
row=1, col=1)
fig.add_trace(go.Bar(x=df2_2['Brand'], y=df2_1['Model']),
row=1, col=2)
fig.update_layout(height=500, width=700,
title_text="Multiple Subplots with Titles")
fig.show()