l_plot=[]
for i in range(10):
x=arange(10)
y=random.random(10)
l_plot.append(plt.plot(x, y, '+-'))
plt.xlim(0,12)
plt.legend([item[0] for item in l_plot], map(str, range(10))) #change it to the plot labels say ['Mass = %f'%item for item in range(10)].
plt.savefig('temp.png')
标签必须是字符串,格式化数字to exponential format using ^{} :
我认为最
matplotlib
的方法是在生成图之后发布一个单独的legend()
。根据文档(http://matplotlib.org/api/pyplot_api.html):
因此,在您的情况下,要获得
label = mass
,必须在需要时使用label = "%.1E" % mass
和其他格式选项。很可能你得重新考虑你的
mass
变量。若要获取示例中除数值外手动键入的内容,还需要一个与MASS1
等价的字符串,除非将质量值放入数组中并创建在该数组上迭代的绘图。在这种情况下,您可以根据数组索引动态创建MASSX
标签:相关问题 更多 >
编程相关推荐