LoslegenKostenlos loslegen

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

Diese Übung ist Teil des Kurses

Introduction to Data Visualization with Plotly in Python

Kurs anzeigen

Anleitung zur Übung

  • 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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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 bearbeiten und ausführen