Python 3 code ############################################################## # Newton's method mountain landscape generation as a whole # (Matplotlib Contour plot) ############################################################## from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import matplotlib.figure as fg from matplotlib import cm import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.view_init(azim=45,elev=45) # set view orientation ax.dist = 4.0 # set viewpoint distance ax.set_facecolor([0.0,0.0,0.0]) # set background color n = 8 L = 1.0 dx = 0.0 dy = 0.0 M = 200 def f(Z): return np.e**(-np.abs(Z)) x = np.linspace(-L+dx,L+dx,M) y = np.linspace(-L+dy,L+dy,M) X,Y = np.meshgrid(x,y) Z = X + 1j*Y for k in range(1,n+1): ZZ = Z - (Z**4 + 1)/(4*Z**3) Z = ZZ W = f(Z) # Plot the surface. ax.set_xlim(dx-L,dx+L) ax.set_zlim(dy-L,dy+L) ax.set_zlim(-2.3*L,2*L) ax.axis("off") ax.contourf3D(X, Y, -W, 2*n, cmap="flag") plt.show()