开始使用免费开始使用

颜色、线型与图例

西雅图市在弗里蒙特大桥上安装了计数器,分别记录桥梁东西两侧(桥体走向为南北向)的自行车通行量。

您将使用 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()
编辑并运行代码