【发布时间】:2015-05-21 08:03:30
【问题描述】:
我的代码如下所示:
pos = 0
x = [1,2,3]
y = [2,3,4]
y2 = [3,5,3]
fig, axs = plt.subplots(1,2)
for pos in [0,1]:
h1 = axs[pos].scatter(x,y,c='black',label='scttr')
h2 = axs[pos].plot(x,y2,c='red',label='line')
axs[pos].legend([h1, h2])
plt.show()
生成正确的图例,没有文本(它在句柄中显示对象名称)。如果我尝试为标签生成一些文本:
pos = 0
x = [1,2,3]
y = [2,3,4]
y2 = [3,5,3]
fig, axs = plt.subplots(1,2)
for pos in [0,1]:
h1 = axs[pos].scatter(x,y,c='black',label='scttr')
h2 = axs[pos].plot(x,y2,c='red',label='line')
axs[pos].legend([h1, h2],['smtng', 'smtng2')
plt.show()
代码因以下原因崩溃:
可以使用代理艺术家代替。看: http://matplotlib.org/users/legend_guide.html#using-proxy-artist
"#using-proxy-artist".format(orig_handle))
我真的不明白 proxy artists 是什么,以及为什么我需要一个来做这么基本的事情。
【问题讨论】:
标签: python matplotlib legend subplot