目录
[TOC]
前言
本章节将讲一下三个内容,图例,网格,背景
(一)图例legend
1.默认不带参数的图例
(1)说明:
默认情况下,是自适应的放在图例的位置,需要在绘图的时候,添加Label标识。
在使用plt.legend()显示图例
(2)源代码:
# 导入模块
import matplotlib.pyplot as plt
import numpy as np
# 数据
x = np.linspace(-5, 5, 50)
y1 = x
y2 = x**2
y3 = x**(1/2)
# 绘图
plt.plot(x, y1, "--", label="y1")
plt.plot(x, y2, "o-", label="y2")
plt.plot(x, y3, "-.", label="y3")
# 展示图例
plt.legend()
# 展示
plt.show()
(3)展示效果
2.添加参数的图例
(1)可选参数
参数
说明
默认值
loc=int\string
图例所在的位置
0
fontsize=int\string
图例的文字大小
当前文字的大小
facecolor='b'
图例的背景色
'w'
edgecolor='b'
图例的边框颜色
'w'
title=string
图例的标题
None
shadow=bool
是否显示图例的阴影
F