Contour Plot

Cross-in-Tray Function Pattern

Cross-in-Tray optimization function showing its characteristic cross-shaped valleys with four global minima, using purple to lime colormap.

Output
Cross-in-Tray Function Pattern
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Cross-in-Tray function
x = np.linspace(-10, 10, 300)
y = np.linspace(-10, 10, 300)
X, Y = np.meshgrid(x, y)

Z = -0.0001 * (np.abs(np.sin(X) * np.sin(Y) * np.exp(np.abs(100 - np.sqrt(X**2 + Y**2) / np.pi))) + 1)**0.1

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

# Custom colormap - purple to lime
colors = ['#f3e8ff', '#8b5cf6', '#4927F5', '#6CF527']
cmap = LinearSegmentedColormap.from_list('purple_lime', colors, N=256)

cs = ax.contourf(X, Y, Z, levels=40, cmap=cmap)
ax.contour(X, Y, Z, levels=25, colors='#374151', linewidths=0.3, alpha=0.4)

cbar = plt.colorbar(cs, ax=ax, pad=0.02)
cbar.set_label('f(x, y)', color='#374151', fontsize=11)
cbar.ax.tick_params(colors='#6b7280', labelsize=9)

# Mark the four global minima
minima = [(1.3491, 1.3491), (-1.3491, 1.3491), (1.3491, -1.3491), (-1.3491, -1.3491)]
for mx, my in minima:
    ax.scatter(mx, my, color='#F5276C', s=60, marker='o', zorder=5, edgecolor='white', linewidth=1)

ax.set_xlabel('x', fontsize=11, color='#374151')
ax.set_ylabel('y', fontsize=11, color='#374151')
ax.set_title('Cross-in-Tray Function Pattern', 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