I would like to still show all x axis values even when the y values are zero for that bar. What am I doing wrong here?
JavaScript
x
16
16
1
import plotly.express as px
2
import plotly.io as pio
3
4
threshold_one = ['13%', '13%', '13%', "34%", "34%", "34%", "55%", "55%", "55%"]
5
threshold_two = ["15%", "37.5%", "60%", "15%", "37.5%", "60%", "15%", "37.5%", "60%"]
6
y_values = [5500,5267,5466,345,356,375,0,0,0]
7
8
9
df = pd.DataFrame({'threshold_one': threshold_one, 'threshold_two': threshold_two, 'y_values': y_values})
10
11
fig = px.histogram(df, x="threshold_one", y="y_values",
12
color="threshold_two",
13
barmode = 'group')
14
15
fig.show()
16
As you can see, x axis threshold one = 55% is missing from the x axis, but I would like it to still be there even though the y values are 0.
Thanks in advance
Advertisement
Answer
Use px.bar
instead of px.histogram
.
JavaScript
1
16
16
1
import plotly.express as px
2
3
threshold_one = ['13%', '13%', '13%', "34%", "34%", "34%", "55%", "55%", "55%"]
4
threshold_two = ["15%", "37.5%", "60%", "15%", "37.5%", "60%", "15%", "37.5%", "60%"]
5
y_values = [5500,5267,5466,345,356,375,0,0,0]
6
7
8
df = pd.DataFrame({'threshold_one': threshold_one, 'threshold_two': threshold_two, 'y_values': y_values})
9
10
fig = px.bar(df, x="threshold_one", y="y_values",
11
color="threshold_two",
12
barmode = 'group')
13
14
fig.show()
15
16