3D Surface

Himmelblau's Function

Multi-modal optimization function with four identical local minima.

Output
Himmelblau's Function
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

colors = ['#0a0a0f', '#581c87', '#ec4899', '#06b6d4', '#22d3ee']
cmap = LinearSegmentedColormap.from_list('magenta_cyan', colors, N=256)

X = np.linspace(-5, 5, 100)
Y = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(X, Y)
Z = (X**2 + Y - 11)**2 + (X + Y**2 - 7)**2  # Himmelblau
Z = np.log10(Z + 1)  # Log scale

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('log₁₀(f+1)', color='white', fontsize=10)
ax.set_title("Himmelblau's 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

Did this help you?

Support PyLucid to keep it free & growing

Support