In this article, we will explore how to create waterfall plots using the Plotly graph_objects module.”
Let’s dive in.
Basic Waterfall Chart
The code provided below illustrates how to create a simple waterfall plot using graph_objects.Waterfall function.
stage = ['intial', 'dependencies', 'database', 'caching', 'post_production', 'refactor', 'production']
compile_time = [1.2, 13.11, 15.67, 11.91, 23.21, 13.31, 8.88 ]
fig = go.Figure(data=go.Waterfall(
x=stage,
y=compile_time
))
fig.show()
The code above will plot a waterfall chart showing the compile time of a project over various stages.
The resulting figure is as shown:
Specifying Plot Orientation
We can specify the orientation of the figure using the orientation parameter as shown below:
stage = ['intial', 'dependencies', 'database', 'caching', 'post_production', 'refactor', 'production']
compile_time = [1.2, 13.11, 15.67, 11.91, 23.21, 13.31, 8.88 ]
fig = go.Figure(data=go.Waterfall(
y=stage,
x=compile_time,
orientation='h',
))
fig.show()
This will set the figure orientation to horizontal as shown:
To set the title for the figure and show the legend, you can use the update_layout function as shown:
stage = ['intial', 'dependencies', 'database', 'caching', 'post_production', 'refactor', 'production']
compile_time = [1.2, 13.11, 15.67, 11.91, 23.21, 13.31, 8.88 ]
fig = go.Figure(data=go.Waterfall(
y=stage,
x=compile_time,
orientation='h',
))
fig.update_layout(title = 'compile time at different stages', showlegend=True)
fig.show()
The output figure is as shown:
Closing
In this article, we discussed the fundamentals of creating waterfall charts using the Plotly graph_objects module.
Thanks for reading & Happy coding!!