Exercise: Advanced Subpots
Explore advanced customization techniques in Plotly by building multi-plot subplots including bar charts, scatter plots, and pie charts. Understand how to arrange, style, and share axes and colorbars in complex visualizations using real company revenue data.
We'll cover the following...
Exercise 1
For this exercise, we will explore a subset of the world’s largest companies by consolidated revenue, according to the Fortune Global 500 2022 rankings. Create a 1x2 subplot with the first plot being a bar chart with the x-axis as the company name and the y-axis as the revenue. The second plot should look at the relationship between the number of employees a company has and the company’s revenue.
Solution
-
The
make_subplots()function on line 2 from theplotly.subplotsmodule is used to create a 1x2 subplot, where therowsparameter specifies the number of rows, and thecolsparameter specifies the number of columns. Thesubplot_titlesparameter is used to add titles to each subplot. -
The first plot is a bar chart created using the
go.Bar()function on line 7 from theplotly.graph_objsmodule. Thexparameter specifies the variable for the x-axis (company name), and theyparameter specifies the variable for the y-axis (revenue). The marker parameter ...