Exercise: Advanced Subpots

Practice with some lab exercises.

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.

Press + to interact
# Setup
companies = pd.read_csv('/usr/local/csvfiles/largest_companies_by_revenue.csv')
print(companies.head())

Solution

  • The make_subplots() function on line 2 from the plotly.subplots module is used to create a 1x2 subplot, where the rows parameter specifies the number of rows, and the cols parameter specifies the number of columns. The subplot_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 the plotly.graph_objs module. The x parameter specifies the variable for the x-axis (company name), and the y parameter specifies the variable for the y-axis (revenue). The marker parameter ...