当前位置:网站首页>Using Matplotlib to add an external image at the canvas level

Using Matplotlib to add an external image at the canvas level

2022-06-26 04:45:00 I am a little monster

import matplotlib.pyplot as plt 
from matplotlib.cbook import get_sample_data
from matplotlib.patches import Rectangle


imageArray=plt.imread('D:/ personal /1.jpg')

fig,ax=plt.subplots(1,1)
ai=ax.imshow(imageArray)
patch=Rectangle((1,0),200,3600)# Provide a graphic to crop the picture 
ai.set_clip_path(patch)# Use the graphics provided above to crop the picture 

ax.set_axis_off()# Eliminate the coordinate axis on the canvas 

plt.show()

 

fig=plt.figure()

imageData1=plt.imread(r'D:\ personal \1.jpg') Read images 

'''figimage Add an image to the canvas , And set the status of the image on the canvas 
   imageData1: Select to display to numpy An image file stored in the form of an array 
    origin: Set the starting point of the coordinate axis (0,0) Set in the upper left corner of the coordinate axis 
    alpha: Set transparency 
     resize: Whether to make the image size fit the canvas size 
     zorder: Prevent hierarchy of image file on canvas , The greater the numerical , Getting ahead '''
fig.figimage(imageData1,200,100,origin='upper',alpha=0.5,resize=True,zorder=1)

fig.savefig(r'D:\ personal \fig.svg')# Save image 

  Open the saved file according to the saved path to see the effect  

原网站

版权声明
本文为[I am a little monster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180510154021.html