python3 and matplotlib: change background color of anchored text

Viewed 1095

Ok I am new to this community and I hope this is not a "too noob" question but I can not find out how to change the color of the background in an AnchoredText in python3.

This is my code so far:

ax2.set_xticklabels([])
ax2.set_yticklabels([])

anchored_text = AnchoredText(s=text_str, loc=2, prop=Afont)
ax2.add_artist(anchored_text)
# anchored_text.set_bbox({'facecolor':blue})
# anchored_text.txt.set_bbox({'facecolor':blue})

Afont = {'family': 'serif',
        # 'facecolor': 'blue',
        'color':  'white',
        'weight': 'normal',
        'size': 14,
        }

and none of the commented lines does the trick.

There must be a way to do it but I am stuck for now. How can I do it?

1 Answers

Ok, it seems it was both easy and hard. In the Aform I can add backgroundcolor attribute and change it.

This is the way to do it:

Afont = {'family': 'serif',
        'backgroundcolor': 'blue',
        'color':  'white',
        'weight': 'normal',
        'size': 14,
        }
Related