Matplotlib 是一个 Python 的绘图库,它提供了一整套用于创建各种图表的接口。下面是一些基本的使用方法:

安装

首先,确保你已经安装了 Python。然后,使用以下命令安装 Matplotlib:

pip install matplotlib

基本图表

以下是一个简单的折线图示例:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

plt.plot(x, y)
plt.show()

折线图示例

子图

Matplotlib 允许你在一个图表中创建多个子图。以下是一个示例:

import matplotlib.pyplot as plt

fig, axs = plt.subplots(2, 1)

axs[0].plot([1, 2, 3], [1, 4, 9])
axs[1].bar([1, 2, 3], [1, 4, 9])

plt.show()

子图示例

扩展阅读

想要了解更多关于 Matplotlib 的内容,可以访问我们的 Matplotlib 详细教程

希望这个简单的教程能帮助你入门 Matplotlib!🎉