開始使用免費開始

顏色、線型與圖例

西雅圖市在弗里蒙特橋(Fremont Bridge)上安裝了計量器,會記錄橋梁東、西兩側的自行車流量;這座橋是南北向。

你將使用 matplotlib 來探索一天當中兩側車流如何變化。了解早晚通勤時段兩側的使用情況,對於未來規劃連接此高流量路線的自行車基礎建設十分重要。

本練習屬於課程

給 MATLAB 使用者的 Python

檢視課程

練習說明

  • 以橘色繪製 northbound_traffic,並標記為「Northbound」。
  • 以紫色繪製 southbound_traffic,並標記為「Southbound」。
  • 將 x 軸標示為「Hour of day」,y 軸標示為「Average number of crossings」。
  • 建立圖例並顯示圖表。

動手互動練習

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

# Plot the northbound traffic in orange and southbound in purple
plt.plot(____, ____='Northbound', ____='orange')
plt.____

# Label your axes
____('Hour of day')
____('Average number of crossings')

# Create a legend and show the plot
plt.____()
plt.show()
編輯並執行程式碼