Revenue histogram with stacked bars
The New York Stock exchange firm thought your previous histogram provided great insight into how the revenue of the firms they are looking at is distributed.
However, like before, they are interested in learning a bit more about how the industry of the firms could shed more light on what is happening.
Your task is to re-create the histogram of company revenues, as before, but include the specified colors based on the list of industries given below.
There is a revenues
DataFrame already loaded for your use.
Industry-color RGB definitions:
- Tech = 124, 250, 120
- Oil = 112,128,144
- Pharmaceuticals = 137, 109, 247
- Professional Services = 255, 0, 0
This exercise is part of the course
Introduction to Data Visualization with Plotly in Python
Exercise instructions
- Create a dictionary to map the different
Industry
values to the RGB codes noted above. - Create a histogram of
revenues
, setting the x-axis to be the company revenue. - Use the industry color map you created in the histogram plot construction.
- Set the appropriate column for the
color
argument.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create the industry-color map
ind_color_map = {'Tech': ____, 'Oil': ____,
'Pharmaceuticals': ____,
'Professional Services': ____}
# Create a simple histogram
fig = px.histogram(
# Set the data and x variable
data_frame=____, x=____, nbins=5,
# Set the color map and variable
color_discrete_map=____,
color=____)
# Show the plot
fig.show()