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

 时间:2024-10-13 02:49:10

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

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

2、接着设置图的大小,添加子图,figsize用于设置图的大小:

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

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

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

4、然后,我们只需要一行代码,plt.legend(loc='位置'), 把图例加上了:

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

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

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

6、一个好看的图例:

python如何在matplotlib中绘制图例legend?
  • MATLAB如何解决参考页要求登陆无法查看的问题
  • cscarctanx怎么算
  • R语言绘制基本的条形图
  • matlab怎么自动备份文件
  • 如何使用python语言中的array进行访问数组
  • 热门搜索
    梦见鸡是什么意思 鬼吹灯什么时候更新 韩国购物买什么 动物的脚印都像什么 toast是什么意思 倚老卖老的意思 额头窄颧骨高适合什么发型 代理商是什么意思 好友克隆是什么意思 淳淳教诲的意思