開始使用免費開始

並排的營收盒鬚圖與色彩

你先前任職的紐約證券交易所(NYSE)公司委託你,延伸你先前建立的公司營收盒鬚圖。

他們想用相同的視覺化方式,瞭解不同產業之間的比較。此外,他們對各產業所使用的顏色也有特定要求,並已準備好產業清單與對應色彩如下。

你的任務是和之前一樣建立公司營收的盒鬚圖,但這次要依下方提供的產業清單套用指定的顏色。

已經為你載入一個可使用的 revenues DataFrame。

產業對應的 RGB 色彩定義

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

本練習屬於課程

Python 的 Plotly 資料視覺化入門

檢視課程

練習說明

  • 建立一個字典,將每個 Industry 對應到其 RGB 顏色。
  • revenues 建立盒鬚圖,y 軸使用 Revenue
  • 將你建立的產業色彩對照表套用到圖上。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create the industry-color map
ind_color_map = {"Tech": ____, "Oil": ____, 
                 "Pharmaceuticals": ____, "Professional Services": ____}

# Create a box plot
fig = px.____(
  			# Set the data and y variable
  			data_frame=____, y="____",
  			# Set the color map 
			____=____,
			color="Industry")

# Show the plot
fig.show()
編輯並執行程式碼