在Matplotlib中如何设置图表的标题和轴标签
文章标签
matplotlib
要在Matplotlib中设置图表的标题和轴标签,可以使用以下方法:
- 设置标题:
plt.title('Title of the plot')
- 设置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()
版权声明
本文仅代表作者观点,不代表米安网络立场。
上一篇:深圳云主机被攻击如何解决 下一篇:Seaborn如何设置图表元素的透明度
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。