我目前是通过matplotlib这种方式生成图例的:
if t==25:
l1,l2 = ax2.plot(x320,vTemp320,'or',x320,vAnaTemp320,'-r')
elif t==50:
l3,l4 = ax2.plot(x320,vTemp320,'ob',x320,vAnaTemp320,'-b')
else:
l5,l6 = ax2.plot(x320,vTemp320,'og',x320,vAnaTemp320,'-g')
plt.legend((l1,l2,l3,l4,l5,l6), ('t=25 Simulation', 't=25 Analytical','t=50 Simulation', 't=50 Analytical','t=500 Simulation', 't=500 Analytical'),
bbox_to_anchor=(-.25, 1), loc=2, borderaxespad=0.,prop={'size':12})
一些方法可行,参见1。但我图例中有重复信息。
我希望将图例分开。所以我需要不同颜色的线对应于时间t。并且普通线作为我的解析解,并且用点来表示模拟结果。
类似于:
-- (红线) t = 25
-- (蓝线) t = 50
-- (绿线) t = 500
o 模拟结果
-- 解析解
请问有人知道我如何在matplotlib中实现这个?
当前图像如下:
artist
,类Artist
. - Mad Physicist(Line2D((0),(0)...), Line2D((1),(0),... )
,然后使用handler_map={tuple: HandlerTuple(ndivide=None)}
。更多信息请参见:https://matplotlib.org/stable/gallery/text_labels_and_annotations/legend_demo.html - lyinch