import numpy as np from scipy.optimize import minimize import matplotlib.pyplot as plt f = lambda x: x*np.sin(7*x)*np.exp(-(x - 2)**2) g = lambda x0: minimize(f, x0, method="CG").x x0s = np.arange(-3, 3, 0.001) xs = [g(x0) for x0 in x0s] plt.plot(x0s, xs) plt.show()