本教程将介绍如何在 Python 中进行基本的绘图操作。我们将使用 matplotlib 库来创建各种图表。

安装 matplotlib

首先,确保你已经安装了 matplotlib 库。如果没有,可以使用以下命令进行安装:

pip install matplotlib

创建基本图表

以下是一个简单的例子,展示如何使用 matplotlib 创建一个折线图。

import matplotlib.pyplot as plt

# 数据
x = [0, 1, 2, 3, 4]
y = [0, 1, 4, 9, 16]

# 创建图表
plt.plot(x, y)

# 添加标题和标签
plt.title('简单折线图')
plt.xlabel('X 轴')
plt.ylabel('Y 轴')

# 显示图表
plt.show()

简单折线图

扩展阅读

想要了解更多关于 Python 绘图的知识,可以阅读以下文章:

希望这个教程能帮助你入门 Python 绘图!