I would like to make a vertical waterfall graph with plotly express. I have a lot of bars to display, that makes my chart unreadable. Is it possible to enlarge the height and width of a ploty graph, even if it means scrolling to visualize parts of the graph ?
Let's take an exemple to illustrate my problem (my real graph has much more bars) :
import plotly.graph_objects as go
import pandas as pd
L_y = [10000,2000,-1000,3000,500,-4000,1000,1000,1500,14000,2500,-1000,2000,0,-1000,1000,1500,1000,20000,-500,-2000,1000,-500,-1000,-2000,1000,1500,17500]
L_x = ["Amount 2019","A - 2020","B - 2020","C - 2020","D - 2020","E - 2020","F - 2020","G - 2020","H - 2020",
"Amount 2020","A - 2021","B - 2021","C - 2021","D - 2021","E - 2021","F - 2021","G - 2021","H - 2021",
"Amount 2021","A - 2022","B - 2022","C - 2022","D - 2022","E - 2022","F - 2022","G - 2022","H - 2022","Amount 2022"]
L_m = ["absolute","relative","relative","relative","relative","relative","relative","relative","relative","total",
"relative","relative","relative","relative","relative","relative","relative","relative","total",
"relative","relative","relative","relative","relative","relative","relative","relative","total"]
df = pd.DataFrame(
{
"X" : L_x,
"Y" : L_y,
"Measure" : L_m,
"Comment" : ["Comment to make"]*28
}
)
df["Text"] = df["Y"].apply(lambda x : "{:,.0f}€".format(x) if x<0 else "+{:,.0f}€".format(x))
fig = go.Figure()
fig.add_trace(go.Waterfall(
x = df['X'], y = df['Y'],
measure = df['Measure'],
base = 0,
text = df['Text'],
textposition = 'outside',
decreasing = {"marker":{"color":"crimson"}},
increasing = {"marker":{"color":"forestgreen"}},
totals = {"marker":{"color":"mediumblue"}},
hovertext = df['Comment'],
))
fig.update_traces(hovertemplate = "%{x}<br>%{text}<br>Comment : %{hovertext}<extra></extra>")
fig.update_layout(
#yaxis_tickformat = ',.2%',
title_text = "Title of graph",
title_font = dict(size=15,color='black')) #title_font = dict(size=15,family='Verdana',color='black'))
fig.update_layout({
'plot_bgcolor': 'rgba(0,0,0,0)',
'paper_bgcolor': 'rgba(0,0,0,0)',
},
hovermode = "x"
)
fig.update_xaxes(showspikes=True, spikecolor = 'black', showline=True, linewidth=1,linecolor='black', ticks = "outside", tickwidth = 1, tickcolor = 'black',ticklen = 5)
fig.update_yaxes(showspikes=True, spikecolor = 'black', showline=True, linewidth=1,linecolor='black', ticks = "outside", tickwidth = 1, tickcolor = 'black',ticklen = 5)
fig.update_yaxes(title = 'Y title' , range = [9000,21000])
fig.update_xaxes(title = "X title")
fig.show()
The graph is difficult to read : enlarging the height and the width of the graph would help a lot to read it (even if it means scrolling), do you know how to do ?