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