Matplotlib 图例:将方形图例更改为圆形
要将方形的图例改为圆形的,可以使用Circle类来创建圆形的Patch对象,然后将其添加到图例元素列表中。\n\n以下是修改后的代码:\n\npython\n# 创建圆形patch\ncircle_patch = Circle((0, 0), radius=0.5, fc='red')\n# 创建图例元素\nlegend_elements = [circle_patch, \n Patch(color='#1A7D1A'), \n Patch(color='#9F67BF'),\n Patch(color='#f29ca3'),\n Patch(color='#2aa6de'),\n Patch(color='#282727')]\n# 创建图例\nplt.legend(handles=legend_elements, loc='upper right', labels=['2012','2016','2018','2019','other years'])\n\n\n注意,将圆形的Patch对象添加到图例元素列表的第一个位置,以确保它显示在图例中的第一个位置。
原文地址: https://www.cveoy.top/t/topic/pSsZ 著作权归作者所有。请勿转载和采集!