11import matplotlib .pyplot as plt
22import pandas as pd
33
4- def plot_comparison (dataset_1 , dataset_2 , title , legend_1 , legend_2 , output_file ):
4+ def plot_comparison_set_counts (dataset_1 , dataset_2 , title , legend_1 , legend_2 , output_file ):
55 dataset_1_local = pd .read_csv (f"{ dataset_1 } _subpop_set_counts.csv" , index_col = 0 )
66 dataset_2_local = pd .read_csv (f"{ dataset_2 } _subpop_set_counts.csv" , index_col = 0 )
77 dataset_1_global = pd .read_csv (f"{ dataset_1 } _metapop_set_counts.csv" , index_col = 0 )
@@ -28,10 +28,48 @@ def plot_comparison(dataset_1, dataset_2, title, legend_1, legend_2, output_file
2828 plt .savefig (output_file )
2929
3030
31+ def plot_comparison_gini (dataset_1 , dataset_2 , title , legend_1 , legend_2 , output_file ):
32+ dataset_1_local = pd .read_csv (f"{ dataset_1 } _subpop_gini.csv" , index_col = 0 )
33+ dataset_2_local = pd .read_csv (f"{ dataset_2 } _subpop_gini.csv" , index_col = 0 )
34+ dataset_1_global = pd .read_csv (f"{ dataset_1 } _metapop_gini.csv" , index_col = 0 )
35+ dataset_2_global = pd .read_csv (f"{ dataset_2 } _metapop_gini.csv" , index_col = 0 )
3136
32- def metapopulation_plot_comparison (dataset_1 , dataset_2 , title , legend_1 , legend_2 , output_file , dataset_3 = None , legend_3 = None ):
33- dataset_1_global = pd .read_csv (f"{ dataset_1 } _metapop_set_counts.csv" , index_col = 0 )
34- dataset_2_global = pd .read_csv (f"{ dataset_2 } _metapop_set_counts.csv" , index_col = 0 )
37+ plt .plot (dataset_1_local .mean (axis = 1 ), color = 'xkcd:sky blue' )
38+ plt .plot (dataset_1_global .mean (axis = 1 ), color = 'xkcd:blue' )
39+ plt .plot (dataset_2_local .mean (axis = 1 ), color = 'tan' )
40+ plt .plot (dataset_2_global .mean (axis = 1 ), color = 'xkcd:puce' )
41+
42+ plt .fill_between (dataset_1_local .index , dataset_1_local .mean (axis = 1 ) - dataset_1_local .std (axis = 1 ), dataset_1_local .mean (axis = 1 ) + dataset_1_local .std (axis = 1 ), color = 'xkcd:sky blue' , alpha = 0.3 )
43+ plt .fill_between (dataset_2_local .index , dataset_2_local .mean (axis = 1 ) - dataset_2_local .std (axis = 1 ), dataset_2_local .mean (axis = 1 ) + dataset_2_local .std (axis = 1 ), color = 'tan' , alpha = 0.3 )
44+ plt .fill_between (dataset_1_global .index , dataset_1_global .mean (axis = 1 ) - dataset_1_global .std (axis = 1 ), dataset_1_global .mean (axis = 1 ) + dataset_1_global .std (axis = 1 ), color = 'xkcd:blue' , alpha = 0.3 )
45+ plt .fill_between (dataset_2_global .index , dataset_2_global .mean (axis = 1 ) - dataset_2_global .std (axis = 1 ), dataset_2_global .mean (axis = 1 ) + dataset_2_global .std (axis = 1 ), color = 'xkcd:puce' , alpha = 0.3 )
46+
47+ plt .axvline (500 , color = "black" , linestyle = '--' , ymax = 1 )
48+
49+ plt .legend ([f"{ legend_1 } subpop avg" , f"{ legend_1 } whole metapop" , f"{ legend_2 } subpop avg" , f"{ legend_2 } whole metapop" ])
50+ plt .ylabel ("Number of feature sets" )
51+ plt .xlabel ("Generations (x100)" )
52+ plt .grid (linestyle = ':' , linewidth = 0.5 )
53+ plt .title (title )
54+
55+ plt .savefig (output_file )
56+
57+
58+ def metapopulation_plot_comparison (dataset_1 , dataset_2 , title , legend_1 , legend_2 , output_file , what_measure , dataset_3 = None , legend_3 = None ):
59+ if what_measure == 'set_counts' :
60+ dataset_1_global = pd .read_csv (f"{ dataset_1 } _metapop_set_counts.csv" , index_col = 0 )
61+ dataset_2_global = pd .read_csv (f"{ dataset_2 } _metapop_set_counts.csv" , index_col = 0 )
62+ elif what_measure == 'shannon' :
63+ dataset_1_global == pd .read_csv (f"{ dataset_1 } _metapop_shannon.csv" , index_col = 0 )
64+ dataset_2_global = pd .read_csv (f"{ dataset_2 } _metapop_shannon.csv" , index_col = 0 )
65+ elif what_measure == 'simpson' :
66+ dataset_1_global = pd .read_csv (f"{ dataset_1 } _metapop_simpson.csv" , index_col = 0 )
67+ dataset_2_global = pd .read_csv (f"{ dataset_2 } _metapop_simpson.csv" , index_col = 0 )
68+ elif what_measure == 'gini' :
69+ dataset_1_global = pd .read_csv (f"{ dataset_1 } _metapop_gini.csv" , index_col = 0 )
70+ dataset_2_global = pd .read_csv (f"{ dataset_2 } _metapop_gini.csv" , index_col = 0 )
71+ else :
72+ print ("You need to decide what measure you will plot: 'set_counts', 'shannon', 'simpson' or 'gini'?" )
3573
3674 plt .plot (dataset_1_global .mean (axis = 1 ), color = 'xkcd:blue' )
3775 plt .plot (dataset_2_global .mean (axis = 1 ), color = 'xkcd:puce' )
@@ -42,6 +80,7 @@ def metapopulation_plot_comparison(dataset_1, dataset_2, title, legend_1, legend
4280 plt .axvline (500 , color = "black" , linestyle = '--' , ymax = 1 )
4381
4482 if dataset_3 is not None :
83+ # TODO FIX HERE
4584 dataset_3_global = pd .read_csv (f"{ dataset_3 } _metapop_set_counts.csv" , index_col = 0 )
4685 plt .plot (dataset_3_global .mean (axis = 1 ), color = 'xkcd:light purple' )
4786 plt .fill_between (dataset_3_global .index , dataset_3_global .mean (axis = 1 ) - dataset_3_global .std (axis = 1 ), dataset_3_global .mean (axis = 1 ) + dataset_3_global .std (axis = 1 ), color = 'xkcd:light purple' , alpha = 0.3 )
0 commit comments