import matplotlib.pyplot as plt import numpy as np def plot_preset(data): a = data["a"] b = data["b"] min_x = data["min"] max_x = data["max"] # 100 linearly spaced numbers x = np.linspace(min_x, max_x, 100) if data["type"] == "parabola": c = data["c"] y = a * x**2 + b * x + c elif data["type"] == "line": y = a * x + b # setting the axes at the centre fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.spines['left'].set_position('center') ax.spines['bottom'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') # plot the function plt.plot(x,y, 'r') # show the plot plt.show() def plot_points(data): points = data["points"] x = [] y = [] for (xi, yi) in points: x.append(xi) y.append(yi) # setting the axes at the centre fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.spines['left'].set_position('center') ax.spines['bottom'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left') # plot the function plt.plot(x,y, data["mode"]) # show the plot plt.show()