I have the following plotly histogram, where I want to show the distribution of the values for a variable which can have only two categorical values:
I am currently plotting it with
fig = px.histogram(pd.DataFrame(hist_data, columns=['result']), x="result", histfunc='count', histnorm='probability density'
) and the plot is correct, but both bins are blue and I would like to have them of two different colors.
So I tried to do the following:
fig = px.histogram(pd.DataFrame(hist_data, columns=['result']), x="result", histfunc='count', histnorm='probability density', color="result", color_discrete_map={value1: color1, value2: color2})
In this way the two bars are correctly colored, but the plot is not anymore correct!
The two bars have both value 1, they don't represent anymore the distribution of the values of the variable result.
edit: for maximum clearness, hist_data
is a list containing only no disease
or cardiovascular disease
as values:
hist_data = ['no disease',
'cardiovascular disease',
'no disease',
'no disease',
'cardiovascular disease',
'cardiovascular disease',
'cardiovascular disease',
'cardiovascular disease',
'cardiovascular disease',
'no disease', ... ]