當前位置:首頁 » 高清圖片 » bbox節目製作背景圖片
擴展閱讀
女生和渣男搞笑圖片 2023-08-31 22:07:09
嘻嘻長什麼樣圖片 2023-08-31 22:06:10

bbox節目製作背景圖片

發布時間: 2023-03-08 07:53:23

A. python 做界面時如何使圖片保持透明背景

#coding=utf-8
#matplotlib背景透明示例圖
#python3.5

importnumpyasnp
importmatplotlib.pyplotasplt
frompylabimportmpl
importscipy.statsasstats

#設置中文字體
mpl.rcParams['font.sans-serif']=['SimHei']


defautolabel(rects):
#attachsometextlabels
forrectinrects:
height=rect.get_height()
#設置標注文字及位置
ax.text(rect.get_x()+rect.get_width()/2,0.03+height,'%.4f'%height,ha='center',va='bottom')

#數據
testData=[[0.87,0.40,0.56],
[0.97,0.50,0.33],
[0.88,0.30,0.44],
[0.25,0.23,0.17],
[0.73,0.33,0.45]]

N=3
width=0.5
ind=np.arange(width,width*6*N,width*6)

fig,ax=plt.subplots()
rectsTest1=ax.bar(ind,(testData[0][0],testData[0][1],testData[0][2]),width,color=(0,0,1,1),edgecolor=(0,0,1,1))

rectsTest2=ax.bar(ind+width,(testData[1][0],testData[1][1],testData[1][2]),width,color=(1,0,0,1),edgecolor=(1,0,0,1))

rectsTest3=ax.bar(ind+2*width,(testData[2][0],testData[2][1],testData[2][2]),width,color=(0,1,0,1),edgecolor=(0,1,0,1))

rectsTest4=ax.bar(ind+3*width,(testData[3][0],testData[3][1],testData[3][2]),width,color=(1,0.6471,0,1),edgecolor=(1,0.6471,0,1))

rectsTest5=ax.bar(ind+4*width,(testData[4][0],testData[4][1],testData[4][2]),width,color=(0.5804,0,0.8275,1),edgecolor=(0.5804,0,0.8275,1))

ax.set_xlim(0,9.5)
ax.set_ylim(0,1.4)
ax.set_ylabel('數值')
ax.yaxis.grid(True)
ax.set_xticks(ind+width*2.5)
ax.set_xticklabels(('P','R','F'))

#設置圖例
legend=ax.legend((rectsTest1,rectsTest2,rectsTest3,rectsTest4,rectsTest5),('test1','test2','test3','test4','test5'))
frame=legend.get_frame()
frame.set_alpha(1)
frame.set_facecolor('none')#設置圖例legend背景透明

#給每個數據矩形標注數值
autolabel(rectsTest1)
autolabel(rectsTest2)
autolabel(rectsTest3)
autolabel(rectsTest4)
autolabel(rectsTest5)

plt.savefig('C:/Users/XX/Desktop/test.png',format='png',bbox_inches='tight',transparent=True,dpi=600)#bbox_inches='tight'圖片邊界空白緊致,背景透明