pyplot 制表符

pyplot tab character(pyplot 制表符)
本文介绍了pyplot 制表符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

我的代码是:

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

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

Does anyone know why this doesn't work?

推荐答案

我很惊讶 pylab.show 实际上显示了一些空格来代替你的正方形.但是 savefig 并没有试图变得聪明并给出您所描述的内容.现在,一个制表符占用多少个空格?这个问题没有意义.4适合你吗?我会为我选择4.2.这意味着您需要决定您希望标签在文本中占用多少空格,即:

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 	 test".replace("	", "    ")
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 	 test".expandtabs()

这篇关于pyplot 制表符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to find element by part of its id name in selenium with python(如何使用python在selenium中通过其id名称的一部分查找元素)
NoSuchElementException: Message: Unable to locate element while trying to click on the button VISA through Selenium and Python(NoSuchElementException:消息:尝试通过 Selenium 和 Python 单击 VISA 按钮时无法找到元素) - IT屋-程序员软件开发技术分
Selenium not able to click on Get Data button on using Python(Selenium 在使用 Python 时无法单击“获取数据按钮)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python(selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素不可点击
Selenium Compound class names not permitted(不允许使用硒化合物类名称)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element while trying to click Next button with selenium(selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:尝试使用 selenium 单