I need to build an expression graph and a graph set by an array of points, and return the images. To build an expression graph, I use sympy.plot
, and to build a graph on points I use matplotlib
.
Here is an example code:
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
x, y are generators. How can I combine these images at one?
sympy.plot
is using MatPlotLib to do the actual work here. – Laurettelaurimatplotlib
as a backend" – Laurettelauri