简体   繁体   English

当文本中有特殊字符时,如何调整figtext的行距?

[英]How do I adjust figtext line spacing for when I have special characters in the text?

I'm trying to add an subscript to some text for my figure caption. 我正在尝试为图形标题添加一些下标。 When I do this, the line with the subscript (line 2) moves up into the line above it (line 1). 当我这样做时,带有下标的行(第2行)将向上移动到其下一行(第1行)。 Is there easy any way around this issue? 有没有解决此问题的简便方法? Using plt.text(...) seems like it could be tedious and time consuming. 使用plt.text(...)似乎很乏味且耗时。

If I don't use any special characters (ie $_{Sun}$) with figtext it works perfectly for me. 如果我在figtext中不使用任何特殊字符(即$ _ {Sun} $),则对我来说非常合适。

I also had something similar happen when I was doing the same thing with legend labels, so I'm guessing that any solution to this problem will solve that as well. 当我使用图例标签执行相同的操作时,我也会发生类似的情况,因此我猜想该问题的任何解决方案也将解决该问题。

Below is the relevant code which I used: 以下是我使用的相关代码:

import numpy as np

import matplotlib.pyplot as plt

from pylab import *

plt.figure(1)

figtext(0.02,0.02,"Standard composition model, Spherical geometry\nT = 5000 K, log(g) = 3.0, Microturbulance = 2, Mass = 2M$_{Sun}$\nThe x-axis covers the range of the K-bandpass\n")

plt.show()

Thank you in advanced! 谢谢高级!

This should have be a comment, if picture can be embedded in a comment. 如果图片可以嵌入评论中,则应为评论。 Anyway, this appears to be a bug in the interactive backend (in the following case, it is the MacOSX backend), when you save the plot into a .png or .pdf, etc, it will be rendered correctly. 无论如何,这似乎是交互式后端中的一个错误(在以下情况下,它是MacOSX后端),当将图保存为.png或.pdf等时,它将正确呈现。

Interactive: 互动: 在此处输入图片说明 Save it as .png or use plt.savefig() : 将其另存为.png或使用plt.savefig() 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM