我需要构建一个表达式图和一个由点数组设置的图,并返回图像。要构建表达式图,我使用sympy.plot,并在我使用的点上构建图matplotlib。
这是一个示例代码:
from os import remove
from matplotlib import pyplot as plt
from PIL import Image
from sympy import plot, symbols
def plot_graphic(x, y, expression, file_name):
file = '{}.png'.format(file_name)
x1, y1 = list(x), list(y)
plt.plot(x1, y1)
plt.savefig(file)
plt.close()
del y1
img = Image.open(file)
remove(file)
yield img
x = symbols('x')
plot(expression.args[1], (x, x1[0], x1[-1]), show=False).save(file)
img = Image.open(file)
remove(file)
yield img
Run Code Online (Sandbox Code Playgroud)
x, y 是生成器。如何将这些图像合二为一?