python中图例legend标签内容_python – matplotlib自定义图例中类别的子标题

我有一个看起来像这样的数字:

我想制作一个看起来像这样的传奇:

我怎样才能做到这一点?

更新:

请注意,此图例的框架带有edgecolor:有效的答案将包括此.图例也应嵌入轴中.

我想要的传奇可能无法使用ax.legend()实现.一个很好的答案将展示如何使用补丁和文本手动构建我想要的图例(完全如图所示),或任何有意义的matplotlib方法.

解决方法

D和A线的单独标题:

from matplotlib.pyplot import *

ds = [1,2,3]

dc = [1.1,1.9,3.2]

asim = [1.5,2.2,3.1]

ac = [1.6,2.15,3.1]

categories = ['simulated','calculated']

p1,= plot(ds,'ko',label='D simulated')

p2,= plot(dc,'k:',label='D calculated')

p3,= plot(asim,'b+',label='A simulated')

p4,= plot(ac,'b-',label='A calculated')

p5,= plot([0],marker='None',linestyle='None',label='dummy-tophead')

p7,label='dummy-empty')

leg3 = legend([p5,p1,p2,p5,p3,p4],[r'$D_{etc}$'] + categories + [r'$A_{etc}$'] + categories,loc=2,ncol=2) # Two columns,vertical group labels

leg4 = legend([p5,p7,[r'$D_{etc}$','',r'$A_{etc}$',''] + categories + categories,loc=4,horizontal group labels

gca().add_artist(leg3)

#If there isn't a big empty spot on the plot,two legends:

#leg1 = legend([p1,p2],categories,title='D_etc',loc=0)

#leg2 = legend([p3,title='A_etc',loc=4)

#gca().add_artist(leg2)

show()

你可能感兴趣的:(python中图例legend标签内容_python – matplotlib自定义图例中类别的子标题)