Hello,
I would like to have two x-axis titles to my barchart.
I was able to add them but my second x-axis title isnt appearing.
import plotly.graph_objects as go
import string
unstacked = go.Bar(
y=[37, 25, 21, 17, 14],
base=0,
width=0.45,
offset=0,
textposition='auto',
texttemplate='%{y}'
)
stackedbottom = go.Bar(
y=[24, 10, 9, 11],
base=0,
width=0.45,
offset=0.45,
textposition='auto',
texttemplate='%{y}'
)
stackedtop = go.Bar(
y=[13, 15, 12, 0, 8],
width=0.45,
offset=0.45,
base=[24, 10, 9, 0, 0],
textposition='auto',
texttemplate='%{y}'
)
fig = go.Figure(data=[unstacked, stackedbottom, stackedtop])
letters = list(string.ascii_uppercase[:5])
ticktext = []
tickvals = []
width = 0.45
for k in range(0, 5):
tickvals.extend([0.5 * width + k, 1.5 * width + k])
for letter in letters:
ticktext.extend([f'{letter}1', f'{letter}2'])
fig.update_layout(xaxis_tickvals=tickvals,
xaxis_ticktext=ticktext,
xaxis_range=[-0.2, 5],
annotations=[dict(x=X, y=Y, text=t, xref='x', yref='paper',
showarrow=False) for X, Y, t in zip([0.45, 1.45, 2.45, 3.45, 4.45], [1.07]*5, [201, 202, 203, 204, 205])])
for k in range(4):
fig.add_vline(x=k + 0.95)
# Adding layout to the figure
fig.update_layout(
title="Double X Axis Example",
xaxis=dict(title="Categories"),
xaxis2=dict(title="Rooms", overlaying='x', side='top'),
yaxis=dict(title="Y values")
)
fig.show()