I am creating a marimekko chart. My code is as follows:
# Create percentage columns
df['Inside_perc'] = (df['Inside'] / (df['Inside'] + df['Other'] + df['Travel'] + df['Dining'] + df['Gas'])) * 100
df['Other_perc'] = (df['Other'] / (df['Inside'] + df['Other'] + df['Travel'] + df['Dining'] + df['Gas'])) * 100
df['Travel_perc'] = (df['Travel'] / (df['Inside'] + df['Other'] + df['Travel'] + df['Dining'] + df['Gas'])) * 100
df['Dining_perc'] = (df['Dining'] / (df['Inside'] + df['Other'] + df['Travel'] + df['Dining'] + df['Gas'])) * 100
df['Gas_perc'] = (df['Gas'] / (df['Inside'] + df['Other'] + df['Travel'] + df['Dining'] + df['Gas'])) * 100
# Create total columnms
df['Sum'] = df['Inside'] + df['Other'] + df['Travel'] + df['Dining'] + df['Gas']
'''Create data and color lists'''
data = {"Inside": df['Inside_perc'],
"Other": df['Other_perc'],
"Travel": df['Travel_perc'],
"Dining": df['Dining_perc'],
"Gas": df['Gas_perc']}
colors= {"Inside": '#001739',
"Other": '#D8D8D8',
"Travel": '#AECEFF',
"Dining": '#93E7FF',
'Gas': '#BFBFBF'}
'''Define horizontal lenghth'''
sum = df['Sum']
widths = sum
x_width = sum.sum()
'''Define labels'''
labels = ['FY19', 'FY20', 'FY21', 'FY22', 'FY23', 'FY24']
'''Plot the marimekko'''
fig = go.Figure()
for key in data:
fig.add_trace(go.Bar(name = key,
y = data[key],
x = np.cumsum(widths) - widths,
width = widths, offset = 0,
marker = {'color' : colors[key]},
customdata = data[key],
texttemplate = "%{y:.0f}",
textposition = "inside",
textangle = 0,textfont_color = "white",
textfont_size = 1))
fig.update_layout(title={'text': "Costco Card Net Sales Category",
'xanchor': 'center',
'yanchor': 'top'})
fig.update_layout(title_text = "M",
barmode = "stack",
title_font_size = 12,legend_font_size = 12,
width = 2000, height = 500)
fig.update_xaxes(title_text=
'Width of each bar = Net Sales($B)',
range = [0, x_width],
title_font_size = 14,
tickvals = np.cumsum(widths)-widths/2,
ticktext =["%s<br>%d"% (l, w) for l,w
in zip(labels, widths)],
tickfont = dict(family='Arial',
color='#002D72', size=12))
fig.update_yaxes(title_text = 'Percentage (%)',
range = [0,100],
title_font=dict(size=16,
family='Arial', color='#002D72'))
fig.update_layout(
autosize=False,
width=1500,
height=600)
fig.show()
At issue is the font size. The font size changes with the area of rectangle. So when the area is very small the font size becomes very difficult to read. I can't seem to get the font size to be the same regardless of the area. Or remove font size all together.