Aan de slagGa gratis aan de slag

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 examining is distributed.

However, like before, they are interested in learning a bit more about how the firms' industries 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

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with Plotly in Python

Cursus bekijken

Oefeninstructies

  • Create a histogram of revenues, using Revenue as the x-axis.
  • Apply the industry color map you created.
  • Set the appropriate column for the color argument.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create the industry-color map
ind_color_map = {"Tech": "rgb(124, 250, 120)", "Oil": "rgb(112, 128, 144)", 
                 "Pharmaceuticals": "rgb(137, 109, 247)", 
                 "Professional Services": "rgb(255, 0, 0)"}

# Create a 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()
Code bewerken en uitvoeren