python - 如何更改offsetbox TextArea的字体颜色

标签 python matplotlib text colors

from matplotlib.offsetbox import TextArea
rc('font',**{'family': 'Courier New, monospace', 'size' : 26})

fig, ax = plt.subplots()
txt = TextArea("Hello World!")
text = AnnotationBbox(txt, (0, 0, 0))
ax.add_artist(text)

有什么办法可以改变这个文本的颜色吗? 谢谢!

最佳答案

Textarea有一个参数 textprops 可用于设置文本的颜色。

import matplotlib.pyplot as plt
from matplotlib.offsetbox import TextArea, AnnotationBbox

fig, ax = plt.subplots()
txt = TextArea("Hello World!", textprops=dict(color="crimson"))
text = AnnotationBbox(txt, (0.5, 0.5))
ax.add_artist(text)

plt.show()

enter image description here

关于python - 如何更改offsetbox TextArea的字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49224993/

相关文章:

python - 在 SQLite SELECT 语句中使用 Python 正则表达式代码

python - 如何使用流读取音频文件?

python - 使用 Matplotlib 和 csv2rec 设置数据类型

java - 能够查看每个类(class)的文本

python - 如何在 Django 中提供创建的临时文件

python - 使用带有 MacOSX 后端的 python matplotlib 设置图形的绝对位置

python - 使matplotlib python中的hexbin填充方轴上的空白区域?

javascript - DGrid 编辑器 - 尝试编辑文本单元格时更改显示值

javascript - 使用 Javascript 从 Qt WebView 获取文本

python - DJango 1.8 在子模板上使用完全不同的 CSS