44import matplotlib .pyplot as plt
55import pandas as pd
66import seaborn as sns
7+ import numpy as np
78
89
910class Plots :
@@ -39,6 +40,9 @@ def plot(
3940 base_folder , x_axis , y_axis , data_point_values , algorithm , save
4041 )
4142 pass
43+ if plot_type == "confidence" :
44+ self .plot_confidence (base_folder , x_axis , y_axis , save )
45+ pass
4246
4347 def get_heatmap_data (
4448 self , base_folder , x_axis , y_axis , data_points , algorithm
@@ -130,26 +134,37 @@ def get_line_chart_data(self, base_folder, x_axis, y_axis):
130134
131135 data_gn_df = pd .DataFrame (
132136 {f"{ x_axis } " : x_values , f"{ y_axis } " : data_gn }
133- )
137+ ). sort_values ( by = f" { x_axis } " )
134138 data_louvain_df = pd .DataFrame (
135139 {f"{ x_axis } " : x_values , f"{ y_axis } " : data_louvain }
136- )
140+ ). sort_values ( by = f" { x_axis } " )
137141 data_lpa_df = pd .DataFrame (
138142 {f"{ x_axis } " : x_values , f"{ y_axis } " : data_lpa }
139- )
143+ ). sort_values ( by = f" { x_axis } " )
140144 data_infomap_df = pd .DataFrame (
141145 {f"{ x_axis } " : x_values , f"{ y_axis } " : data_infomap }
142- )
146+ ). sort_values ( by = f" { x_axis } " )
143147 data_gm_df = pd .DataFrame (
144148 {f"{ x_axis } " : x_values , f"{ y_axis } " : data_gm }
145- )
146-
149+ ).sort_values (by = f"{ x_axis } " )
150+
151+ data = pd .DataFrame ({
152+ f"{ x_axis } " : x_values ,
153+ "LPA" : data_lpa ,
154+ "Infomap" :data_infomap ,
155+ "GM" : data_gm ,
156+ "Louvain" : data_louvain ,
157+ "GN" : data_gn })
158+
159+ test_df = pd .melt (data , [f"{ x_axis } " ])
160+
147161 return (
148162 data_gn_df ,
149163 data_louvain_df ,
150164 data_lpa_df ,
151165 data_infomap_df ,
152166 data_gm_df ,
167+ test_df
153168 )
154169
155170 def plot_heatmap (
@@ -159,7 +174,7 @@ def plot_heatmap(
159174 base_folder , x_axis , y_axis , data_point_values , algorithm
160175 )
161176 plt .figure (figsize = (20 , 20 ))
162- sns .heatmap (heatmap_data , annot = True , fmt = ".2f" , linewidth = 0.5 )
177+ sns .heatmap (heatmap_data , annot = True , fmt = ".2f" , linewidth = 0.5 , vmin = 0 , vmax = 1 )
163178
164179 # plt.contourf(heatmap_data.columns, heatmap_data.index, heatmap_data.values, 20, cmap="viridis", alpha=0.6)
165180 # plt.colorbar(label=data_point_values)
@@ -186,7 +201,7 @@ def plot_heatmap(
186201 plt .show ()
187202 plt .clf ()
188203
189- def plot_line_chart (self , base_folder , x_axis , y_axis , save ):
204+ def old_plot_line_chart (self , base_folder , x_axis , y_axis , save ):
190205 (
191206 data_gn ,
192207 data_louvain ,
@@ -201,42 +216,46 @@ def plot_line_chart(self, base_folder, x_axis, y_axis, save):
201216 data_infomap = data_infomap .sort_values (by = f"{ x_axis } " )
202217 data_gm = data_gm .sort_values (by = f"{ x_axis } " )
203218
204- plt .figure (figsize = (10 , 6 ))
205219
220+ fig , ax = plt .subplots (1 , 1 , figsize = (15 , 10 ))
206221 plt .plot (
207222 data_gn [f"{ x_axis } " ],
208223 data_gn [f"{ y_axis } " ],
224+ "ro--" ,
209225 label = "Girvan Newman" ,
210- color = "blue" ,
211226 )
212227 plt .plot (
213228 data_louvain [f"{ x_axis } " ],
214229 data_louvain [f"{ y_axis } " ],
230+ "ko--" ,
215231 label = "Louvain" ,
216- color = "black" ,
217232 )
218233 plt .plot (
219234 data_lpa [f"{ x_axis } " ],
220235 data_lpa [f"{ y_axis } " ],
236+ "co--" ,
221237 label = "LPA" ,
222- color = "green" ,
223238 )
224239 plt .plot (
225240 data_infomap [f"{ x_axis } " ],
226241 data_infomap [f"{ y_axis } " ],
242+ "go--" ,
227243 label = "Infomap" ,
228- color = "gray" ,
229244 )
230245 plt .plot (
231246 data_gm [f"{ x_axis } " ],
232247 data_gm [f"{ y_axis } " ],
248+ "mo--" ,
233249 label = "Greedy Modularity" ,
234- color = "pink" ,
235250 )
236251
252+
253+ ax .set (xlim = (0 ,100 ), ylim = (0 ,1 ))
254+ ax .set_yticks (np .arange (0 , 1 , 1 / 10 ))
255+ ax .set_yticks (np .arange (0 , 1 , 1 / 50 ), minor = True )
256+ ax .set_xticks (np .arange (0 , 100 , 100 / 10 ))
237257 plt .xlabel (f"{ x_axis } " )
238258 plt .ylabel (f"{ y_axis } " )
239- plt .title (f"Devolopment of { y_axis } over { x_axis } " )
240259 plt .legend ()
241260 plt .grid (True )
242261
@@ -249,3 +268,69 @@ def plot_line_chart(self, base_folder, x_axis, y_axis, save):
249268 plt .savefig (filename , dpi = 300 )
250269 plt .show ()
251270 plt .clf ()
271+
272+ def plot_line_chart (self , base_folder , x_axis , y_axis , save ):
273+ (
274+ data_gn ,
275+ data_louvain ,
276+ data_lpa ,
277+ data_infomap ,
278+ data_gm ,
279+ test
280+ ) = self .get_line_chart_data (base_folder , x_axis , y_axis )
281+
282+ fig , ax = plt .subplots (1 , 1 , figsize = (15 , 10 ))
283+
284+ sns .lineplot (data = test , x = x_axis , y = 'value' , hue = 'variable' , style = "variable" , markers = True , dashes = True )
285+
286+ ax .set (xlim = (0 ,100 ), ylim = (0 ,1 ))
287+ ax .set_yticks (np .arange (0 , 1 , 1 / 10 ))
288+ ax .set_yticks (np .arange (0 , 1 , 1 / 50 ), minor = True )
289+ ax .set_xticks (np .arange (0 , 100 , 100 / 10 ))
290+ plt .xlabel (f"{ x_axis } " )
291+ plt .ylabel (f"{ y_axis } " )
292+ plt .legend ()
293+ plt .grid (True )
294+
295+ if save :
296+ base_dir = os .path .join ("exports/plots/" )
297+ filename = (
298+ base_dir + f"line-chart-{ y_axis } -over-{ x_axis } -{ self .name } .png"
299+ )
300+ os .makedirs (base_dir , exist_ok = True )
301+ plt .savefig (filename , dpi = 300 )
302+ plt .show ()
303+ plt .clf ()
304+
305+ def plot_confidence (self , base_folder , x_axis , y_axis , save ):
306+ (
307+ data_gn ,
308+ data_louvain ,
309+ data_lpa ,
310+ data_infomap ,
311+ data_gm ,
312+ test
313+ ) = self .get_line_chart_data (base_folder , x_axis , y_axis )
314+
315+ fig , ax = plt .subplots (1 , 1 , figsize = (15 , 10 ))
316+
317+ sns .lineplot (data = test , x = x_axis , y = 'value' )
318+
319+ ax .set (xlim = (0 ,100 ), ylim = (0 ,1 ))
320+ ax .set_yticks (np .arange (0 , 1 , 1 / 10 ))
321+ ax .set_yticks (np .arange (0 , 1 , 1 / 50 ), minor = True )
322+ ax .set_xticks (np .arange (0 , 100 , 100 / 10 ))
323+ plt .xlabel (f"{ x_axis } " )
324+ plt .ylabel (f"{ y_axis } " )
325+ plt .legend ()
326+ plt .grid (True )
327+
328+ if save :
329+ base_dir = os .path .join ("exports/plots/" )
330+ filename = (
331+ base_dir + f"line-chart-{ y_axis } -over-{ x_axis } -{ self .name } .png"
332+ )
333+ os .makedirs (base_dir , exist_ok = True )
334+ plt .savefig (filename , dpi = 300 )
335+ plt .show ()
336+ plt .clf ()
0 commit comments