Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Design: palettes, chart styles, faces and network drawings#
Interactive evolution has served graphic design since the 1990s (Takagi, 2001). The design problems here mix judged qualities with computable constraints: a colour palette must keep text legible (WCAG contrast ratio of at least 4.5 : 1); a chart style should be clean and readable; Chernoff faces (Chernoff, 1973) map ten numbers to facial features that people read instantly; a network drawing should show the structure of Zachary’s karate club without clutter.
Random designs#
import matplotlib.pyplot as plt
import numpy as np
import easyiec as ei
from easyiec.problems import ChartStyle, ChernoffFace, ColorPalette, GraphLayout
from easyiec.strategies import InteractiveCMAES
rng = np.random.default_rng(6)
families = [ColorPalette(), ChartStyle(), ChernoffFace(), GraphLayout()]
fig, axes = plt.subplots(4, 6, figsize=(10, 7))
for row, p in zip(axes, families):
for ax in row:
ax.imshow(p.to_image(p.random(rng), 140))
ax.axis("off")
row[0].set_title(p.title, fontsize=8, loc="left")
fig.tight_layout()

A legible palette#
The default utility of ColorPalette rewards WCAG
contrast between text and background and between the data series and the
background, and a spread of hues.
problem = ColorPalette()
user = ei.SimulatedUser(problem, target="default", noise=0.03, seed=2)
res = ei.run(problem, InteractiveCMAES(pop_size=8), user, generations=12, seed=2)
print({k: round(v, 2) for k, v in problem.objectives(res.best.genome).items()})
ei.viz.plot_history(res.log, problem, steps=[0, 5, 11], max_items=8, size=1.1)
plt.show()

{'text_contrast': 6.13, 'series_contrast': 4.12, 'hue_spread': 0.66}
Total running time of the script: (0 minutes 1.140 seconds)