繪製每小時逮捕率
在這個練習中,你要用 hourly_arrest_rate 物件建立折線圖。由於要呈現某個數量隨時間的變化,折線圖很合適。
這張圖可以幫你發現,僅看原始數字時不容易看出的趨勢!
本練習屬於課程
使用 pandas 分析警方執法活動
練習說明
- 匯入
matplotlib.pyplot並使用別名plt。 - 使用
.plot()方法為hourly_arrest_rate繪製折線圖。 - 將 x 軸標籤設為
'Hour',y 軸標籤設為'Arrest Rate',並將圖表標題設為'Arrest Rate by Time of Day'。 - 使用
.show()函式顯示圖表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import matplotlib.pyplot as plt
# Create a line plot of 'hourly_arrest_rate'
# Add the xlabel, ylabel, and title
plt.xlabel(____)
plt.ylabel(____)
plt.title(____)
# Display the plot