在Python/Matplotlib中加下划线的文字 [英] Underlining Text in Python/Matplotlib

查看:366
本文介绍了在Python/Matplotlib中加下划线的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到与此主题相关的其他主题或文档-有没有人成功地在python matplotlib软件包中强调了这一点?对于所有其他属性,我使用的语法是这样的:

I couldn't find another thread or documentation on this topic - has anyone ever been successful underlining in pythons matplotlib package? The syntax I am using is something like this for all the other attributes:

plt.text(0.05, 0.90, 'Parameters: ', fontsize=12)

但是,除了实际在文件中编码一行之外,我不知道该如何在此文本下划线.

However, I can't figure out how to underline this text short of actually coding a line into the file.

有想法吗?

推荐答案

Matplotlib可以使用LaTeX处理所有文本,请参见此文档的本页以获取更多信息.在LaTeX中为文本加下划线的命令只是\underline.从示例脚本之一的文档字符串开始:

Matplotlib can use LaTeX to handle all text, see this page of the documnetation for more information. The command for underlining text in LaTeX is simply \underline. From the docstring of one of the example scripts:

如果设置了rc参数text.usetex,则可以使用TeX渲染所有matplotlib文本.这目前在aggps后端上有效,并且要求您具有tex和

You can use TeX to render all of your matplotlib text if the rc parameter text.usetex is set. This works currently on the agg and ps backends, and requires that you have tex and the other dependencies described at http://matplotlib.sf.net/matplotlib.texmanager.html properly installed on your system. The first time you run a script you will see a lot of output from tex and associated tools. The next time, the run may be silent, as a lot of the information is cached in ~/.tex.cache

因此,我们可以做一个简单的例子

So as a simple example we can do

import matplotlib.pyplot as plt
from matplotlib import rc

rc('text', usetex=True)

plt.sunplot(111)

plt.text(0.05, 0.90, r'\underline{Parameters}: ', fontsize=12)

获取带下划线的文本.

这篇关于在Python/Matplotlib中加下划线的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆