Contour Plot

Levy Function Landscape

Levy benchmark function with complex multimodal optimization landscape.

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

x = np.linspace(-10, 10, 200)
y = np.linspace(-10, 10, 200)
X, Y = np.meshgrid(x, y)

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)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

colors = ['#fdf4ff', '#e879f9', '#F527B0', '#86198f']
cmap = LinearSegmentedColormap.from_list('pink', colors, N=256)

cs = ax.contourf(X, Y, Z, levels=30, cmap=cmap)
ax.contour(X, Y, Z, levels=15, colors='#701a75', linewidths=0.4, alpha=0.5)
cbar = plt.colorbar(cs, ax=ax, pad=0.02)
cbar.set_label('log(f(x,y))', color='#374151', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='#374151')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#374151')

ax.set_xlabel('X', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Y', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Levy Function Landscape', fontsize=14, color='#1f2937', fontweight='bold', pad=15)

ax.tick_params(colors='#6b7280', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support