#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  4 14:57:19 2026

@author: leonhardtm
"""

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pathlib import Path

plt.rcParams['axes.labelsize']=18

fig, axs = plt.subplots(2,3,figsize=(18,8),sharex='col', sharey='row')
plt.subplots_adjust(hspace=0.1,wspace=0.07)

MS=['.','s',"$o$",'v','d','*','p','v']
C=['C0','C1','C2','gold','C9','C4','C8','C5','C3','C7','C6']

NC=np.array([2,3,4,5,6,7])


for j in range(len(NC)):
    nc=NC[j]
    X=pd.read_csv(Path(__file__).resolve().parent.parent/"DATA"/"FIG2"/'StableSteadyStates_nc_{}.csv'.format(nc))
    X_data=X.to_numpy()
    n_col=np.shape(X_data)[1]
    
    m=0
    if j>2:
        m=1
        
    for i in range(n_col-1):
        if i==0:
            axs[m,j%3].plot(X_data[:,0],X_data[:,i+1],'.',color=C[i],markersize=5,label=X.columns[i+1],linestyle='None')
        else:
            axs[m,j%3].plot(X_data[:,0],X_data[:,i+1],marker=MS[i],color=C[i],markersize=3,label=X.columns[i+1],linestyle='None')




plt.setp(axs[1,:], xlabel=r'$g(\omega_C)$')
plt.setp(axs[:,0], ylabel=r'$Z_\mathrm{tot}/n_c$')


axs[0,0].set_yticks(np.array([0,-0.1,-0.2,-0.3,-0.4,-0.5]))
axs[1,0].set_yticks(np.array([0,-0.1,-0.2,-0.3,-0.4,-0.5]))

axs[0,0].set_title(r'$n_c=2$',y=0.97,pad=-14,x=0.02,loc='left',fontsize=18)
axs[0,1].set_title(r'$n_c=3$',y=0.97,pad=-14,x=0.02,loc='left',fontsize=18)
axs[0,2].set_title(r'$n_c=4$',y=0.97,pad=-14,x=0.02,loc='left',fontsize=18)
axs[1,0].set_title(r'$n_c=5$',y=0.97,pad=-14,x=0.02,loc='left',fontsize=18)
axs[1,1].set_title(r'$n_c=6$',y=0.97,pad=-14,x=0.02,loc='left',fontsize=18)
axs[1,2].set_title(r'$n_c=7$',y=0.97,pad=-14,x=0.02,loc='left',fontsize=18)

axs[0,0].tick_params(labelsize=18)
axs[0,1].tick_params(labelsize=18)
axs[1,0].tick_params(labelsize=18)
axs[1,1].tick_params(labelsize=18)
axs[0,2].tick_params(labelsize=18)
axs[1,2].tick_params(labelsize=18)

axs[0,0].legend(loc=4,fontsize=16)
axs[0,1].legend(loc=4,fontsize=16)
axs[0,2].legend(loc=4,fontsize=16)
axs[1,0].legend(loc=4,fontsize=16)
axs[1,1].legend(loc=4,fontsize=16)
axs[1,2].legend(loc=4,fontsize=16)


#### INSETS
## 4 clusters
Z=pd.read_csv(Path(__file__).resolve().parent.parent/"DATA"/"FIG2"/'StableSteadyState_bifurcation_nc_4.csv')
Z_data=Z.to_numpy()

U=pd.read_csv(Path(__file__).resolve().parent.parent/"DATA"/"FIG2"/'UnstableSteadyState_bifurcation_nc_4.csv')
U_data=U.to_numpy()

plt.figure(figsize=(2,2.3))
plt.plot(Z_data[:,0],Z_data[:,1],linestyle='None',marker='s',color='C1',markersize=3.5)
plt.plot(U_data[:,0],U_data[:,1],linestyle='None',marker='s',color='grey',markersize=3.5)

plt.ylim([-0.452,-0.298])
plt.xlim([0.14,0.26])

plt.xticks(fontsize=16)
plt.yticks(fontsize=16)

plt.xlabel(r'$g(\omega_C)$')
plt.ylabel(r'$Z_\mathrm{tot}/n_c$')


## 5 clusters
Z=pd.read_csv(Path(__file__).resolve().parent.parent/"DATA"/"FIG2"/'StableSteadyState_bifurcation_nc_5.csv')
Z_data=Z.to_numpy()

U=pd.read_csv(Path(__file__).resolve().parent.parent/"DATA"/"FIG2"/'UnstableSteadyState_bifurcation_nc_5.csv')
U_data=U.to_numpy()

plt.figure(figsize=(2,2.3))
plt.plot(Z_data[:,0],Z_data[:,1],linestyle='None',marker='s',color='C1',markersize=3.5)
plt.plot(U_data[:,0],U_data[:,1],linestyle='None',marker='s',color='grey',markersize=3.5)

plt.ylim([-0.352,-0.198])
plt.xlim([0.14,0.26])

plt.xticks(fontsize=16)
plt.yticks(fontsize=16)

plt.xlabel(r'$g(\omega_C)$')
plt.ylabel(r'$Z_\mathrm{tot}/n_c$')



