Python matplotlib中的斜体标题为';行不通

Python matplotlib中的斜体标题为';行不通,python,python-2.7,python-3.x,matplotlib,Python,Python 2.7,Python 3.x,Matplotlib,所以我的主要问题是—— 次要文本以普通字体排在第一位,然后主标题(newtitle)以斜体/浅色字体排在后面(看起来很漂亮) newtitle=“%s\n$%s$”%('text\belower\the\main\title',newtitle) 我们可以不使用$符号来完成吗?这是预期的结果吗 可以使用mathtext以快速而肮脏的方式完成,但必须使$剥落每行,例如: import matplotlib.pyplot as plt from textwrap import wrap x_li

所以我的主要问题是——

次要文本以普通字体排在第一位,然后主标题(
newtitle
)以斜体/浅色字体排在后面(看起来很漂亮)

newtitle=“%s\n$%s$”%('text\belower\the\main\title',newtitle)


我们可以不使用
$
符号来完成吗?

这是预期的结果吗

可以使用
mathtext
以快速而肮脏的方式完成,但必须使
$
剥落每行,例如:

import matplotlib.pyplot as plt
from textwrap import wrap

x_list = [11, 3, 6, 5]
label_list = ["red colour", "blue colour", "green colour", "back colour"]

title = "Some really really long long long title I really really need - and just can't - just can't - make it any - simply any - shorter - at all?"

newtitle = '\n'.join(wrap(title, width=50))  # wrap the long title so that it won't get cropped.

# here if I print `newtitle` first then "text below the main title" gets convert into italics
newtitle = "%s\n$%s$"%(newtitle, 'text\ below\ the\ main\ title') 
# but If I print `newtitle` after the secondary text it doesn't convert into italics
newtitle = "%s\n$%s$"%('text\ below\ the\ main\ title', newtitle)  # comment this line for 1st effect

plt.figure(figsize=(7,6), dpi=100)
plt.axis("equal")
plt.subplots_adjust(left=0.1, right=0.8, top=0.7)
plt.rc("font", size=10)
explode = [0.03, 0, 0, 0]

plt.pie(x_list, labels=label_list, explode=explode, autopct="%1.1f%%", startangle=90)
plt.title(newtitle, size=12)

plt.savefig('test.png')
但我认为一个更好看的方法是将这两个标题分开。您可以使用上面的
suptitle
,或者只使用
text
,任何一种方式都可以独立控制它们的属性。e、 g:

newtitle = '\n'.join(['$%s$'%item for item in wrap(title, width=50)]).replace(' ', '\ ')
newtitle = "%s\n%s"%('text\ below\ the\ main\ title', newtitle)

你检查过这个吗:?@SaulloCastro:是的。。但是代码太多了。我想知道这件事是否能巧妙地/很快完成。
plt.pie(x_list, labels=label_list, explode=explode, autopct="%1.1f%%", startangle=90)
plt.title('\n'.join(wrap(title, width=50)), size=12, style='italic')
plt.suptitle('some title', y=0.85, x=0.45) #y and x needed as you have adjusted the subplot size already.