Sunday, May 10, 2009

MPL multicolor text




from pylab import figure, show

from matplotlib.offsetbox import AnchoredOffsetbox, HPacker, TextArea


f = figure(1)
ax = f.add_subplot(111)

txt1 = TextArea("A$^3$", textprops=dict(color="r", size=150))
txt2 = TextArea("gb", textprops=dict(color="k", size=150))

txt = HPacker(children=[txt1, txt2],
align="baseline",
pad=0, sep=0)

def txt_offset(*kl):
return ax.transData.transform_point((0.2, 0.2))
txt.set_offset(txt_offset)

# box = AnchoredOffsetbox(loc=3, pad=0, borderpad=0,
# bbox_to_anchor=(0.5, 0.5),
# bbox_transform=ax.transData,
# child=txt,
# frameon=False)

ax.add_artist(txt)

show()

No comments:

Followers