wrap其实是换行的意思,默认是不换行的(默认值为False)。
这个参数在文本比较长的时候才有用。
具体参见下面的代码
import matplotlib.pyplot as plt
fig = plt.figure()
plt.axis([0, 10, 0, 10])
t = "This is a really long string that I'd rather have wrapped so that it"\
" doesn't go outside of the figure, but if it's long enough it will go"\
" off the top or bottom!"
plt.text(6, 1, t, ha='left', rotation=15, wrap=True) # 上面这串文字自动换行,不会跑出图界
plt.text(6, 5, t, ha='left', rotation=15, wrap=False) # 上面这串文字因为太长又不能换行,越界了
plt.show()
上图代码执行后,得到下图。
另外,来点小拓展性知识:
其实第3个参数string,可以不是字符串,整数和浮点数都可以,见下面的代码。
import matplotlib.pyplot as plt
fig = plt.figure()
plt.axis([0, 10, 0, 10])
t = "This is a really long string that I'd rather have wrapped so that it"\
" doesn't go outside of the figure, but if it's long enough it will go"\
" off the top or bottom!"
plt.text(6, 1, t, ha='left', rotation=15, wrap=True) # 上面这串文字自动换行,不会跑出图界
plt.text(6, 5, 3456, ha='left', rotation=15, wrap=False) # 上面这串文字因为太长又不能换行,越界了
plt.show()