python – How can one plot the progress of an optimization?


Is there a way to plot the progressive value of a function being optimized with scipy.optimize’s differential evolution? In the following the plotting part doesn’t work:

from scipy.optimize import rosen, differential_evolution
bounds = ((0, 5), (0, 5), (0, 5), (0, 5), (0, 5))
result = differential_evolution(rosen, bounds, disp=False)
print(result.x, result.fun)
import matplotlib.pyplot as plt
x, f = zip(*result)
plt.plot(x, f)