Here is my code and how my graph looks like:
go.Bar(
y=[wtdf[WASTE_TYPE].tolist(), wtdf[SUBSTREAM].tolist()],
x=wtdf[WEIGHT],
orientation='h',
marker={'color': [clr_map_mld[clr] for clr in wtdf[WASTE_TYPE].tolist()]},
)
My question is, is it possible to color individual labels like Reusable in yellow, recycling in green?
I think you can use subplots
to make it. I donβt have your data so please refer below code to make yours.
from plotly.subplots import make_subplots
import plotly.graph_objects as go
import pandas as pd
import numpy as np
df = pd.read_excel('Dtaa.xlsx')
df = df.sort_values(['PALAVRA', 'QTD_EVENTOS'], ascending=[True, True]).groupby('PALAVRA').head(10)
df3= df[df['PALAVRA']=='ponte rolante']
df4= df[df['PALAVRA']=='motorista camihao']
df5= df[df['PALAVRA']=='carga suspensa']
fig1=go.Figure(go.Bar(x=df3['QTD_EVENTOS'],
y=[df3['PALAVRA'],
df3['ASSOCIADO']],
orientation='h',
textposition='outside',
text=df3['QTD_EVENTOS'],
marker_color='yellow'))
fig2=go.Figure(go.Bar(x=df4['QTD_EVENTOS'],
y=[df4['PALAVRA'],
df4['ASSOCIADO']],
orientation='h',
textposition='outside',
text=df4['QTD_EVENTOS'],
marker_color='green'))
fig3=go.Figure(go.Bar(x=df5['QTD_EVENTOS'],
y=[df5['PALAVRA'],
df5['ASSOCIADO']],
orientation='h',
textposition='outside',
text=df5['QTD_EVENTOS'],
marker_color='#c0c0c0'))
fig4 = make_subplots(rows=3, cols=1,
shared_xaxes=True,
vertical_spacing=0.01)
fig4.append_trace(fig1.data[0], row=1, col=1)
fig4.append_trace(fig2.data[0], row=2, col=1)
fig4.append_trace(fig3.data[0], row=3, col=1)
fig4.update_layout(height=600)
fig4.show()