So I have a bar chart that lets you switch between diffirent countries and regions using update buttons, but on activation, the graph position changes horizontally. I’ve tried combining height, width, margin and autosize=False, but nothing seems to work. Does anyone know a solution to this problem that prefferably does not involve changing the scale on the Y-axis?
(I cut the first 6 traces from the code below as they’re similar to trace7 but with diffirent values)
trace7 = go.Bar(
x=post2k1C[post2k1C['country'] == 21]['iyear'],
y=post2k1C[post2k1C['country'] == 21]['cases'],
name='België',visible=False)
layout = go.Layout(
xaxis=go.layout.XAxis(title='Jaar'),
yaxis=go.layout.YAxis(title= 'Aantal terroristische aanslagen'),
title= 'Aantal terroristische aanslagen per jaar per regio in het Westen',
title_x = 0.5,
updatemenus=[
dict(type='buttons', direction='right', x=0.7, y=-0.2, showactive=True,
buttons= [dict(method='update', label='Aanslagen per regio', visible=True,
args=[{'visible':[True, True, True, False, False, False, False, False]},
{'title.text': 'Aantal terroristische aanslagen per jaar per regio in het Westen'}]),
dict(method='update', label='FR, DU, UK', visible=True,
args=[{'visible':[False, False, False, True, True, True, False, False]},
{'title.text': 'Aantal terroristische aanslagen in Frankrijk, Duitland, Verenigd Koninkrijk'}]),
dict(method='update', label='Benelux', visible=True,
args=[{'visible':[False, False, False, False, False, False, True, True]},
{'title.text': 'Aantal terroristische aanslagen in Nederland, België en Luxemburg* '}])
]
)])
fig = go.Figure(data=[trace0, trace1, trace2, trace3, trace4, trace5, trace6, trace7], layout=layout)
Beneath I shall post some images of the fig.show() output to show the movement of the charts.