开始使用免费开始使用

使用 matplotlib.pyplot 接口

使用 Matplotlib 的方式有很多。在本课程中,我们将重点使用 pyplot 接口。它在创建和自定义数据可视化方面最为灵活。

首先,您将使用 pyplot 接口创建两类对象:Figure 对象和 Axes 对象。

本课程会涉及不少新概念。如果您需要快速回顾,可以下载 Matplotlib Cheat Sheet 并随手查阅!

本练习是课程的一部分

Matplotlib 数据可视化入门

查看课程

练习说明

  • 按惯例将 matplotlib.pyplot API 以名称 plt 导入。
  • 使用 plt.subplots 函数创建 FigureAxes 对象。
  • 使用 plt.show 函数显示结果(一个空的坐标轴)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the matplotlib.pyplot submodule and name it plt
import ____ as ____

# Create a Figure and an Axes with plt.subplots
fig, ax = ____

# Call the show function to show the result
____
编辑并运行代码