我尝试打印只有一行的figlegend,但我只收到第一个字母。我有使剧情下面的脚本:Matplotlib:figlegend只打印第一个字母
from pylab import *
k = plot((0, 1),(1, 1))
figlegend((k),('Limit'),loc='lower center')
savefig('test.pdf')
输出是:
我在做什么错? (或者它是一个错误?)
我尝试打印只有一行的figlegend,但我只收到第一个字母。我有使剧情下面的脚本:Matplotlib:figlegend只打印第一个字母
from pylab import *
k = plot((0, 1),(1, 1))
figlegend((k),('Limit'),loc='lower center')
savefig('test.pdf')
输出是:
我在做什么错? (或者它是一个错误?)
我还没有想出它是一个错误还是故意(出于某种原因)在matplotlib,但为了得到一个完整的图例标签,你需要留下尾随的逗号标签列表:
figlegend((k),('Limit',),loc='lower center')
改变该行并代码:
from pylab import *
k = plot((0, 1),(1, 1))
figlegend((k),('Limit',),loc='lower center')
savefig('test.pdf')
生产的数字:
这是Python的一个功能:要指定单元素列表,需要使用该语法将其与parens中的某些标量值区分开来。 http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences –
这是我遇到过的Python中最奇怪的怪癖。非常感谢你发现了这一点。 – GLaDER
'('Limit')'在python中不是作为元组插入的,'('Limit',)'is。我的猜测是'['Limit']'应该工作得很好。 – Hooked