@@ -102,49 +102,80 @@ def plot_CRM(observed_species, observed_resources, timepoints, csv_file=None):
102102
103103 return fig , ax
104104
105- def plot_CRM_with_intervals (observed_species , observed_resources , species_lower , species_upper ,
106- resource_lower , resource_upper , times , filename = None ):
105+
106+ def plot_CRM_with_intervals (
107+ observed_species ,
108+ observed_resources ,
109+ species_lower ,
110+ species_upper ,
111+ resource_lower ,
112+ resource_upper ,
113+ times ,
114+ filename = None ):
107115 fig , ax = plt .subplots (figsize = (12 , 8 ))
108-
116+
109117 # Plot median trajectories
110118 for i in range (observed_species .shape [1 ]):
111- ax .plot (times , observed_species [:, i ], label = f'Species { i + 1 } ' , linewidth = 2 )
112-
119+ ax .plot (times , observed_species [:, i ],
120+ label = f'Species { i + 1 } ' , linewidth = 2 )
121+
113122 for i in range (observed_resources .shape [1 ]):
114- ax .plot (times , observed_resources [:, i ], label = f'Resource { i + 1 } ' , linewidth = 2 , linestyle = '--' )
115-
116- # Add confidence ribbons
123+ ax .plot (times ,
124+ observed_resources [:,
125+ i ],
126+ label = f'Resource { i + 1 } ' ,
127+ linewidth = 2 ,
128+ linestyle = '--' )
129+
130+ # Add confidence ribbons
117131 for i in range (observed_species .shape [1 ]):
118- ax .fill_between (times , species_lower [:, i ], species_upper [:, i ],
119- alpha = 0.2 , color = plt .cm .tab10 (i ))
120-
132+ ax .fill_between (times , species_lower [:, i ], species_upper [:, i ],
133+ alpha = 0.2 , color = plt .cm .tab10 (i ))
134+
121135 for i in range (observed_resources .shape [1 ]):
122- ax .fill_between (times , resource_lower [:, i ], resource_upper [:, i ],
123- alpha = 0.2 , color = plt .cm .tab10 (i + observed_species .shape [1 ]))
124-
136+ ax .fill_between (times ,
137+ resource_lower [:,
138+ i ],
139+ resource_upper [:,
140+ i ],
141+ alpha = 0.2 ,
142+ color = plt .cm .tab10 (i + observed_species .shape [1 ]))
143+
125144 if filename :
126145 true_data = pd .read_csv (filename )
127146 true_times = true_data ['time' ].values
128-
147+
129148 for i in range (observed_species .shape [1 ]):
130149 col_name = f'species_{ i + 1 } '
131150 if col_name in true_data .columns :
132- ax .scatter (true_times , true_data [col_name ],
133- marker = 'o' , s = 30 , color = plt .cm .tab10 (i ), label = f'True { col_name } ' )
134-
151+ ax .scatter (
152+ true_times ,
153+ true_data [col_name ],
154+ marker = 'o' ,
155+ s = 30 ,
156+ color = plt .cm .tab10 (i ),
157+ label = f'True { col_name } ' )
158+
135159 for i in range (observed_resources .shape [1 ]):
136160 col_name = f'resource_{ i + 1 } '
137161 if col_name in true_data .columns :
138- ax .scatter (true_times , true_data [col_name ],
139- marker = 's' , s = 30 , color = plt .cm .tab10 (i + observed_species .shape [1 ]),
140- label = f'True { col_name } ' )
141-
162+ ax .scatter (
163+ true_times ,
164+ true_data [col_name ],
165+ marker = 's' ,
166+ s = 30 ,
167+ color = plt .cm .tab10 (
168+ i + observed_species .shape [1 ]),
169+ label = f'True { col_name } ' )
170+
142171 ax .set_xlabel ('Time' , fontsize = 14 )
143172 ax .set_ylabel ('Concentration' , fontsize = 14 )
144- ax .set_title ('Consumer-Resource Model Dynamics with 95% Credible Intervals' , fontsize = 16 )
173+ ax .set_title (
174+ 'Consumer-Resource Model Dynamics with 95% Credible Intervals' ,
175+ fontsize = 16 )
145176 ax .legend (loc = 'best' , fontsize = 12 )
146177 ax .grid (True , alpha = 0.3 )
147-
178+
148179 plt .tight_layout ()
149180 if filename :
150181 plt .savefig (f"{ filename .split ('.' )[0 ]} _with_intervals.png" , dpi = 300 )
0 commit comments