開始使用免費開始

以堆疊長條呈現的 Revenue 直方圖

紐約證券交易所的團隊認為你先前的直方圖,對於理解該機構正在檢視的公司營收分布相當有幫助。

不過,他們和先前一樣,想更進一步了解各家公司所屬產業,是否能提供更多線索來解讀圖形。

你的任務是重新建立公司的營收直方圖,做法與先前相同,但這次請依下方提供的產業清單套用指定的顏色。

一個名為 revenues 的 DataFrame 已經載入,可直接使用。

產業對應色彩的 RGB 定義

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

本練習屬於課程

Python 的 Plotly 資料視覺化入門

檢視課程

練習說明

  • revenues 繪製直方圖,將 Revenue 作為 x 軸。
  • 套用你建立的產業色彩對照表。
  • 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()
編輯並執行程式碼