Adjusting Text background transparency

前端 未结 1 810
旧时难觅i
旧时难觅i 2021-02-18 19:28

I\'m trying to put some text with a background on a matplotlib figure, with the text and background both transparent. The following code

import numpy as np
impo         


        
1条回答
  •  后悔当初
    2021-02-18 20:00

    The alpha passed to plt.text() will change the transparency of the text font. To change the background you have to change the alpha using Text.set_bbox():

    t = plt.text(0.5, 0.5, 'text', transform=ax.transAxes, fontsize=30)
    t.set_bbox(dict(facecolor='red', alpha=0.5, edgecolor='red'))
    #changed first dict arg from "color='red'" to "facecolor='red'" to work on python 3.6
    

    enter image description here

    0 讨论(0)
提交回复
热议问题