Hi,
In the following code, I have a bar chart with universal text size and two axes. I need to run a dummy for the second axis to populate, but then the universal text size does not work, as shown in the images. Any ideas?
Thanks
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
df = pd.DataFrame({'index': [0, 1, 2, 3, 4, 5, 6, 7],
'name_WWTP': ['Lahti 2', 'Lahti 1', 'Riihimäki', 'Kouvola', 'Hämeenlinna', 'Porvoo', 'Helsinki 1', 'Forssa'],
'PHA': [247, 314, 230, 299, 260, 135, 3184, 175],
'tran_cost_unit': [0.005, 0.005, 0.028, 0.036, 0.036, 0.045, 0.05, 0.059],
'PHA_cum': [247, 561, 790, 1089, 1348, 1483, 4667, 4842]
})
fig = make_subplots(specs=[[{"secondary_y": True}]])
for p in df['name_WWTP'].unique():
dat = df[df.name_WWTP == p]
fig.add_trace(go.Bar(
name=p,
x=dat['PHA_cum']-dat['PHA']/2,
y=dat['tran_cost_unit'],
width=dat['PHA'],
text=dat['name_WWTP'],
textposition='outside',
textangle=-90,
))
fig.update_layout(uniformtext_minsize=12, uniformtext_mode='show')
# This dummy trace messes up the uniform text size.
fig.add_trace(go.Bar(
name=p,
x=dat['PHA_cum']-dat['PHA']/2,
y=[700],
yaxis='y2',
))
fig.update_layout(yaxis2=dict(
title='Distance from Kujala (km)',
titlefont_size=14,
tickfont_size=14,
showgrid=False,
tickvals=[100, 200, 300, 400, 500, 600, 700],
))
fig.show()