# 去除图片的边边
ax = fig.add_axes([0.1, 0.1, 0.7, 0.7])

ax.axis('off')
                plt.gca().xaxis.set_major_locator(plt.NullLocator())
                plt.gca().yaxis.set_major_locator(plt.NullLocator())
                plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=0, wspace=0)
                plt.margins(0, 0)
                plt.savefig(out_file, transparent=True, bbox_inches='tight', dpi=300, pad_inches=0.0,
                            set_visiable=False)

 

from PIL import Image

# 图片改为透明色

img = Image.open(new_file)
img = img.convert("RGBA")
datas = img.getdata()
newData = []
for item in datas:
    if item != (255, 255, 255, 0):
         pass
    if item[0] == 255 and item[1] == 255 and item[2] == 255:
         newData.append((255, 255, 255, 0))
    else:
         newData.append(item)
img.putdata(newData)
img.save('out_file.png', "PNG")