如何更改字体颜色偏移框TextArea

时间:2018-03-11 20:54:34

标签: 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)

有没有办法改变这个文字的颜色? 谢谢!

1 个答案:

答案 0 :(得分:0)

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

相关问题