pyplot制表符

use*_*022 10 python tabs matplotlib

我正在尝试使用pyplot中的制表符.但是,制表符正在显示正方形,而不是我需要的制表符空间.

我的代码是:

fig = pl.figure()
fig.text(.1,.05, "test \t test", bbox=dict(facecolor='red', alpha=0.5))
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么这不起作用?

mmg*_*mgp 9

我很惊讶,pylab.show实际上显示了一些空间代替你的广场.但是savefig不要试图变得聪明并且给出你所描述的内容.现在,一个标签占用了多少个空格?这个问题毫无意义.这是4吗?我会为我挑选4.2.这意味着您需要确定标签在文本中需要多少空格,即:

fig = pylab.figure()
text = "test \t test".replace("\t", "    ")
fig.text(.1,.05, text, bbox=dict(facecolor='red', alpha=0.5))
Run Code Online (Sandbox Code Playgroud)

或者,您可能只想使用"标准"约定来扩展选项卡:

text = "test \t test".expandtabs()
Run Code Online (Sandbox Code Playgroud)