Revenue histogram subplots
The revenue histogram with colors by industry (with stacked bars) you created for the The New York Stock exchange firm was enlightening for which industries tended to be in which area of the histogram.
However, the firm wishes to understand the distribution of each industry without having to hover to see. For this analysis, the previous histogram has too much in a single plot, but they don't want multiple plots. How can you help solve this conundrum?
Your task is to create a histogram of company revenues by industry as a stacked subplot and a shared x-axis to allow meaningful comparison of industries.
You have a revenues
DataFrame loaded for you.
This exercise is part of the course
Introduction to Data Visualization with Plotly in Python
Exercise instructions
- Create the subplots grid with 3 rows and 1 column and make the x-axis shared.
- Loop through the desired industries, adding a histogram trace each time with the industry name.
- Position the trace in the appropriate place in the subplot grid.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the subplots
fig = make_subplots(rows=____, cols=____, ____=True)
# Loop through the industries
row_num = 1
for industry in ['Tech', 'Retail', 'Professional Services']:
df = revenues[revenues.Industry == industry]
# Add a histogram using subsetted df
fig.____(go.____(x=df['Revenue'], name=____),
# Position the trace
row=____, col=____)
row_num +=1
# Show the plot
fig.show()