开始使用免费开始使用

按收入绘制的堆叠柱状直方图

纽约证券交易所的团队认为您之前的直方图很好地展示了他们所研究公司的收入分布。

不过,他们也和之前一样,希望进一步了解不同行业是否能提供更多解释。

您的任务是像之前一样重新绘制公司收入的直方图,但这次需要根据下方给定的行业列表应用指定颜色。

为您准备好的 revenues DataFrame 已经加载。

行业-颜色 RGB 定义

  • Tech = 124, 250, 120
  • Oil = 112, 128, 144
  • Pharmaceuticals = 137, 109, 247
  • Professional Services = 255, 0, 0

本练习是课程的一部分

Python 中的 Plotly 数据可视化入门

查看课程

练习说明

  • revenues 创建直方图,x 轴使用 Revenue
  • 应用您创建的行业颜色映射。
  • color 参数设置合适的列。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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()
编辑并运行代码