Path: blob/main/hybrid-workflows/auxiliary_files/labs_plotting.py
1127 views
import matplotlib.pyplot as plt1import numpy as np23def plot_energy_distributions(results_1, results_2=None, labels=("Experiment 1", "Experiment 2"), n_val=0):4"""5Plots histograms of final energy distributions.67Args:8results_1 (array-like): List of energy values from first experiment.9results_2 (array-like, optional): List of energy values from second experiment.10labels (tuple): Labels for the legend.11n_val (int): Sequence length (for title).12"""13plt.figure(figsize=(10, 6))1415# Determine common bin edges for consistent alignment16all_data = results_117if results_2 is not None:18all_data = np.concatenate([results_1, results_2])1920# Calculate 15 bins based on the full range of data21bins = np.histogram_bin_edges(all_data, bins=15)2223# Plot first set24plt.hist(results_1, bins=bins, alpha=0.6, label=labels[0], color='blue', edgecolor='black')2526# Plot second set if provided27if results_2 is not None:28plt.hist(results_2, bins=bins, alpha=0.6, label=labels[1], color='green', edgecolor='black')2930plt.title(f"LABS Memetic Optimization Results (N={n_val})\nFinal Population Cost Distribution")31plt.xlabel("Energy Cost (Lower is Better)")32plt.ylabel("Frequency in Population")33plt.legend()34plt.grid(True, alpha=0.3)35plt.tight_layout()36plt.show()3738