from mpl_toolkits.mplot3d import Axes3D costPath = np.array([np.log(((X.dot(wtmp)-y)**2).sum()) for wtmp in allw]) costOpt = np.log(((X.dot(wstar)-y)**2).sum()) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_surface(w1, w2, cost, rstride = 1, cstride=1 ) ax.scatter(wstar[0], wstar[1],costOpt, c='r') ax.plot(allw[:,0],allw[:,1],costPath, 'b+-' ,lw=2 )