Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Bar graph color dependent on multiple variables

For a project I am working on I am looking for a way to have the color of individual bars dependent on multiple variables within my data frame (string and boolean). More specifically I want certain bars within my stacked bar graph to be presented with a different color if the Partial Period boolean is true while maintaining different colors for the string values

fig = px.bar(
                        title='{}: {} vs Time'.format(dropdown_value, radio_choice) if dropdown_value else
                        '{}: {} vs Time'.format(list_of_names[-1], radio_choice),
                        data_frame=filtered_df,
                        x='Date of Event',
                        y='Measure Value',
                        color='Variable Name',
                        barmode='group',
                        hover_data=['Partial Period']

I’ve been looking for a way to do this without any luck, and would greatly appreciate it if anyone knows a solution
Thank you

Hi @kcalder welcome to the forum! You can create the figure with plotly express and update the color of bar markers as follows (and you can build the markers_colors array using your Partial Period column)

import plotly.express as px
df = px.data.medals_long()
fig = px.bar(df, x='nation', y='count', color='medal', barmode='group')
fig.update_traces(marker_color=['slateblue', 'lightblue', 'lightblue'], selector={'name':'gold'})
fig.show()