Exercise: Advanced Subpots
Practice with some lab exercises.
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.
# Setupcompanies = pd.read_csv('/usr/local/csvfiles/largest_companies_by_revenue.csv')print(companies.head())
Solution
-
The
make_subplots()
function on line 2 from theplotly.subplots
module is used to create a 1x2 subplot, where therows
parameter specifies the number of rows, and thecols
parameter specifies the number of columns. Thesubplot_titles
parameter 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_objs
module. Thex
parameter specifies the variable for the x-axis (company name), and they
parameter specifies the variable for the y-axis (revenue). The marker parameter ...