import pandas as pd import matplotlib.pyplot as plt # Load the CSV file file_path = r'C:\Users\a_gabald\Desktop\solar_different_efficiencies.csv' # Replace with your file path data = pd.read_csv(file_path) # Assuming the CSV has a datetime column, parse it data['datetime'] = pd.date_range(start='1/1/2023', periods=8760, freq='h') # Set the datetime column as the index data.set_index('datetime', inplace=True) # Resample the data to monthly data monthly_data = data.resample('ME').sum() # Extract data for different efficiencies monthly_16_horizontal = monthly_data['district MWh Horizontal_16%'] monthly_18_horizontal = monthly_data['district MWh Horizontal_18%'] monthly_14_horizontal = monthly_data['district MWh Horizontal_14%'] monthly_16_tilted = monthly_data['district MWh tilted_16%'] monthly_18_tilted = monthly_data['district MWh tilted_18%'] monthly_14_tilted = monthly_data['district MWh tilted_14%'] # Combine the data into a single DataFrame for easier plotting combined_data_horizontal = pd.DataFrame({ 'Month': monthly_data.index.month, 'Horizontal_16%': monthly_16_horizontal, 'Horizontal_18%': monthly_18_horizontal, 'Horizontal_14%': monthly_14_horizontal }) combined_data_tilted = pd.DataFrame({ 'Month': monthly_data.index.month, 'Tilted_16%': monthly_16_tilted, 'Tilted_18%': monthly_18_tilted, 'Tilted_14%': monthly_14_tilted }) # Function to plot box and whisker plot import numpy as np # Function to plot box and whisker plot import matplotlib.pyplot as plt # Function to plot error bars def plot_error_bars(data, title, ylabel): fig, ax = plt.subplots(figsize=(14, 8)) months = range(1, 13) means_16 = [] err_low = [] err_high = [] for month in months: month_data = data[data['Month'] == month] mean_16 = month_data.iloc[:, 1].mean() low_14 = month_data.iloc[:, 3].mean() high_18 = month_data.iloc[:, 2].mean() means_16.append(mean_16) err_low.append(mean_16 - low_14) err_high.append(high_18 - mean_16) ax.errorbar(months, means_16, yerr=[err_low, err_high], fmt='o', capsize=5, capthick=2, ecolor='gray') ax.set_xticks(months) ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']) ax.set_xlabel('Month') ax.set_ylabel(ylabel) ax.set_title(title) plt.show() # Plot for Horizontal plot_error_bars(combined_data_horizontal, 'Monthly District MWh (Horizontal)', 'MWh') # Plot for Tilted plot_error_bars(combined_data_tilted, 'Monthly District MWh (Tilted)', 'MWh')