python如何在matplotlib中绘制图例legend?

2024-10-13 02:49:10

1、首先导入使用到的包,matplotlib.pyplot, numpy:

python如何在matplotlib中绘制图例legend?

3、再接着,我们使用numpy创建正弦,余弦曲线的点集合,并调用plot方法绘制:

python如何在matplotlib中绘制图例legend?

5、但是,我们可能满足于这种显示方式,我想要把图例单独单个显示,拆分出来,这里重要的代码就是,获取到legend ,调用add_artist方法,不然会被覆盖掉,到此,legend图例的操作完成了。

python如何在matplotlib中绘制图例legend?
猜你喜欢