新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

Matplotlib中如何添加网格线,matplotlib figsize

发布时间:2024-05-11 18:42:49

Matplotlib中如何添加网格线

在Matplotlib中添加网格线可使用plt.grid()函数。示例以下:

import matplotlib.pyplot as plt

# 创建一个简单的折线图
x = [1, 2, 3, 4, 5]
y = [10, 15, 13, 18, 16]
plt.plot(x, y)

# 添加网格线
plt.grid(True)

plt.show()

在上面的示例中,plt.grid(True)表示将网格线显示出来。你也能够根据需要自定义网格线的样式,如改变色彩、线型、透明度等。