pyplot tab character

青春壹個敷衍的年華 提交于 2020-05-09 01:25:07

问题


I am trying to use the tab character in pyplot. However, the tab character is displaying a square, not the tab space I require.

My code is:

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

Does anyone know why this doesn't work?


回答1:


I was surprised that pylab.show actually shows some spaces in place of your square. But savefig does not try to be smart and gives what you describe. Now, how many spaces does one tab take ? This question makes no sense. Is it 4 for you ? I will pick 4.2 for me. This means you need to decide how many spaces you want a tab to take in your text, i.e.:

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

Or, maybe you want to simply expand your tabs using "standard" conventions:

text = "test \t test".expandtabs()


来源:https://stackoverflow.com/questions/13964872/pyplot-tab-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!