这似乎是重复的,但我发誓我试图找到一个兼容的答案。在
我有一组相同3个样品的不同性质的柱状图。所以我想要一个有这些树样本名字的图例。在
像“h1”和“h3”一样,定义了相同的直方图:
plt.subplot(121)
plt.hist(variable1[sample1], histtype = 'step', normed = 'yes', label = 'h1')
plt.hist(variable1[sample2], histtype = 'step', normed = 'yes', label = 'h2')
plt.hist(variable1[sample3], histtype = 'step', normed = 'yes', label = 'h3')
plt.subplot(122)
plt.hist(variable2[sample1], histtype = 'step', normed = 'yes', label = 'h1')
plt.hist(variable2[sample2], histtype = 'step', normed = 'yes', label = 'h2')
plt.hist(variable2[sample3], histtype = 'step', normed = 'yes', label = 'h3')
然后我用了:
^{pr2}$图例出现,但为空。有什么想法吗?在
你有两个问题。首先,你误解了
label
的作用。它不标记要通过该名称访问的艺术家,但如果不使用任何参数调用legend
,则提供legend
使用的文本。第二个问题是bar
没有自动生成的图例处理程序。在另请参见http://matplotlib.org/users/legend_guide.html#using-proxy-artist
相关问题 更多 >
编程相关推荐