Linux 拨号vps windows公众号手机端

在Matplotlib中如何设置图表的标题和轴标签

lewis 1年前 (2024-05-03) 阅读数 10 #程序编程
文章标签 matplotlib

要在Matplotlib中设置图表的标题和轴标签,可以使用以下方法:

  1. 设置标题:
plt.title('Title of the plot')
  1. 设置x轴和y轴标签:
plt.xlabel('X-axis label')
plt.ylabel('Y-axis label')

例如,下面是一个完整的示例代码,展示如何设置图表的标题和轴标签:

import matplotlib.pyplot as plt

# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

# 绘制折线图
plt.plot(x, y)

# 设置标题和轴标签
plt.title('Prime numbers')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')

# 显示图表
plt.show()
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门