3D Trisurf

Levy Function Trisurf

Levy optimization test function with global minimum at origin in blue-cyan gradient.

Output
Levy Function Trisurf
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Scattered sampling
np.random.seed(44)
n_points = 600
x = np.random.uniform(-5, 5, n_points)
y = np.random.uniform(-5, 5, n_points)

# Levy function
w_x = 1 + (x - 1) / 4
w_y = 1 + (y - 1) / 4
z = (np.sin(np.pi * w_x)**2 + 
     (w_x - 1)**2 * (1 + 10*np.sin(np.pi*w_x + 1)**2) +
     (w_y - 1)**2 * (1 + np.sin(2*np.pi*w_y)**2))
z = np.log1p(z)

# Custom colormap
colors = ['#ffffff', '#cffafe', '#276CF5', '#27D3F5', '#a5f3fc']
cmap = LinearSegmentedColormap.from_list('blue_cyan', colors, N=256)

fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')

surf = ax.plot_trisurf(x, y, z, cmap=cmap, alpha=0.85, linewidth=0.1, edgecolor='#33333308')

ax.set_xlabel('X', fontsize=10, color='#374151', labelpad=10)
ax.set_ylabel('Y', fontsize=10, color='#374151', labelpad=10)
ax.set_zlabel('log(f+1)', fontsize=10, color='#374151', labelpad=10)
ax.set_title("Levy Function Trisurf", fontsize=14, color='#1f2937', fontweight='bold', pad=20)

ax.tick_params(colors='#6b7280', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#e5e7eb')
ax.yaxis.pane.set_edgecolor('#e5e7eb')
ax.zaxis.pane.set_edgecolor('#e5e7eb')

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