開始使用免費開始

用顏色標示學生分數的長條圖

學校委員會對你先前的圖表很滿意,但他們想知道是否能用視覺化方式辨識表現好與不好的學生。

這正好可以運用顏色,特別是色階。你覺得從紅色(較差成績)到綠色(較好成績)的色階很合適。

已提供部分你先前建立學生分數長條圖的程式碼。

student_scores DataFrame 也已提供。你可以在主控台列印並檢視它。

本練習屬於課程

Python 的 Plotly 資料視覺化入門

檢視課程

練習說明

  • 建立一個從紅色(255, 0, 0)到綠色(3, 252, 40)的色階清單。
  • color 參數設為正確的數值欄位。
  • 在圖中使用 my_scale 作為色階。

動手互動練習

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

# Create your own continuous color scale
my_scale = ["rgb(____)", "rgb(____)"]

# Create the bar plot
fig = px.bar(data_frame=student_scores, 
             x="student_name", y="score", title="Student Scores by Student",
             # Set the color variable and scale
             color="____",
             color_continuous_scale=____
             )

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