import numpy as np
import matplotlib.pyplot as plt
# Define the actual values and predicted values for each algorithm (15 data points, divided by 5)
actual_values = [104.68, 59.82, 116.46, 167.84, 55.52, 173.3, 100.06, 74.66, 40.12, 200.56, 188.58, 137.04, 94.48, 76.9, 158.14]
random_forest = [96.6492, 76.0534, 122.9982, 176.5654, 81.1354, 130.0802, 115.1354, 75.9882, 52.532, 159.3734, 172.6634, 140.48, 104.5, 86.86, 170.04]
adaboost = [92.82, 81.9085714, 124.386, 202.6, 86.24, 127.1814286, 116.96, 81.904, 46.66, 155.54, 202.6, 157.12, 98.54, 81.02, 168.56]
gbdt = [95.98781468, 74.96110086, 117.7310702, 197.42420436, 91.7741229, 124.67256592, 109.2566582, 71.75484286, 45.79896326, 171.22975376, 195.36240668, 150.46, 102.56, 87.12, 174.06]
cbfs_rcv = [107.10204, 72.66388, 124.77712, 184.07366, 90.695404, 140.868188, 107.66706, 60.299772, 48.798538, 199.86112, 182.065528, 148.44, 92.48, 82.82, 170.52]
# Set the x-axis labels (e.g., Test 1, Test 2, ..., Test 15)
test_labels = [f'Test {i}' for i in range(1, 16)]
# Set the width of the bars
bar_width = 0.15
# Calculate the x-axis positions for each set of bars
x = np.arange(len(test_labels))
# Define custom colors for each set of bars
colors = ['#007acc', '#ff6f61', '#5aaf76', '#ffcc29', '#6a0572']
# Create the bar plot with custom colors
with plt.style.context(['ieee', 'no-latex']):
plt.figure(figsize=(10, 6))
plt.bar(x - 2*bar_width, actual_values, width=bar_width, label='Actual Values', align='center', color=colors[0])
plt.bar(x - bar_width, random_forest, width=bar_width, label='Random Forest', align='center', color=colors[1])
plt.bar(x, adaboost, width=bar_width, label='Adaboost', align='center', color=colors[2])
plt.bar(x + bar_width, gbdt, width=bar_width, label='GBDT', align='center', color=colors[3])
plt.bar(x + 2*bar_width, cbfs_rcv, width=bar_width, label='SSA-BP', align='center', color=colors[4])
# Set the x-axis labels and title
plt.xlabel('Test Sample Number', fontsize=14)
plt.ylabel('Open Flow Capacity ($\mathregular{10^4 m^3}$/d)', fontsize=14)
plt.xticks(x, test_labels, fontsize=12)
plt.legend(fontsize=12)
plt.tight_layout()
plt.show()