我想弄清楚如何做同樣的事情。我下了一個兔子洞,想了一下,我還需要使用PIL(Pillow)來完成這項任務。在前面的答案的幫助下,我能夠拿出一個完整的例子:
import matplotlib
from io import BytesIO
import numpy
import matplotlib.pyplot as plt
from wand.display import display
from wand.image import Image
plt.plot([1,5,3,2])
plt.ylabel('y axis numbers')
plt.xlabel('x axis numbers')
image_data = BytesIO() #Create empty in-memory file
plt.savefig(image_data, format='png') #Save pyplot figure to in-memory file
image_data.seek(0) #Move stream position back to beginning of file
img = Image(file=image_data) #Create wand.image
display(img) #Use wand to display the img