3D Surface
Ackley Function
Optimization benchmark with nearly flat outer region and deep hole at origin.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
colors = ['#0a0a0f', '#0c4a6e', '#06b6d4', '#a78bfa', '#c084fc']
cmap = LinearSegmentedColormap.from_list('cyan_purple', colors, N=256)
X = np.linspace(-5, 5, 100)
Y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(X, Y)
# Ackley function
a, b, c = 20, 0.2, 2*np.pi
Z = -a * np.exp(-b * np.sqrt(0.5*(X**2 + Y**2))) - np.exp(0.5*(np.cos(c*X) + np.cos(c*Y))) + a + np.e
fig = plt.figure(figsize=(10, 8), facecolor='#0a0a0f')
ax = fig.add_subplot(111, projection='3d', facecolor='#0a0a0f')
surf = ax.plot_surface(X, Y, Z, cmap=cmap, linewidth=0, antialiased=True)
ax.set_xlabel('X', color='white', fontsize=10)
ax.set_ylabel('Y', color='white', fontsize=10)
ax.set_zlabel('f(x,y)', color='white', fontsize=10)
ax.set_title('Ackley Function', color='white', fontsize=14, fontweight='bold', pad=20)
ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')
ax.view_init(elev=30, azim=45)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
More 3D Surface examples
☕