1212# along with this program. If not, see <http://www.gnu.org/licenses/>.
1313
1414# experiments.py
15- # Copyright (C) 2015-2021 Fracpete (pythonwekawrapper at gmail dot com)
15+ # Copyright (C) 2015-2023 Fracpete (pythonwekawrapper at gmail dot com)
1616
1717import logging
1818import math
2626
2727
2828def plot_experiment (mat , title = "Experiment" , axes_swapped = False , measure = "Statistic" , show_stdev = False ,
29- key_loc = "lower right" , outfile = None , wait = True ):
29+ x_label = None , y_label = None , key_loc = "lower right" , bbox_to_anchor = None , outfile = None , wait = True ):
3030 """
3131 Plots the results from an experiment.
3232
3333 :param mat: the result matrix to plot
3434 :type mat: ResultMatrix
3535 :param title: the title for the experiment
3636 :type title: str
37- :param axes_swapped: whether the axes whether swapped ("sets x cls " or "cls x sets ")
37+ :param axes_swapped: whether the axes whether swapped for the evaluation ("datasets x classifers " or "classifers x datasets ")
3838 :type axes_swapped: bool
3939 :param measure: the measure that is being displayed
4040 :type measure: str
4141 :param show_stdev: whether to show the standard deviation as error bar
4242 :type show_stdev: bool
43+ :param x_label: the label to override the default x label with (ie Classifiers/Datasets)
44+ :type x_label: str
45+ :param y_label: the label to override the default y label with (ie the measure)
46+ :type y_label: str
4347 :param key_loc: the location string for the key
4448 :type key_loc: str
49+ :param bbox_to_anchor: tuple for the key anchor
50+ :type bbox_to_anchor: tuple
4551 :param outfile: the output file, ignored if None
4652 :type outfile: str
4753 :param wait: whether to wait for the user to close the plot
@@ -58,11 +64,11 @@ def plot_experiment(mat, title="Experiment", axes_swapped=False, measure="Statis
5864
5965 fig , ax = plt .subplots ()
6066 if axes_swapped :
61- ax .set_xlabel (measure )
62- ax .set_ylabel ("Classifiers" )
67+ ax .set_xlabel (x_label if x_label is not None else "Datasets" )
68+ ax .set_ylabel (y_label if y_label is not None else measure )
6369 else :
64- ax .set_xlabel ("Classifiers" )
65- ax .set_ylabel (measure )
70+ ax .set_xlabel (x_label if x_label is not None else "Classifiers" )
71+ ax .set_ylabel (y_label if y_label is not None else measure )
6672 ax .set_title (title )
6773 plot .set_window_title (fig , title )
6874 ax .grid (True )
@@ -92,7 +98,7 @@ def plot_experiment(mat, title="Experiment", axes_swapped=False, measure="Statis
9298 else :
9399 ax .plot (x , means , "o-" , label = plot_label )
94100 plt .draw ()
95- plt .legend (loc = key_loc , shadow = True )
101+ plt .legend (loc = key_loc , bbox_to_anchor = bbox_to_anchor , mode = "expand" , shadow = True )
96102 if outfile is not None :
97103 plt .savefig (outfile )
98104 if wait :
0 commit comments