Skip to content

Commit 9e12416

Browse files
committed
made the plot_experiment method more customizable (anchor, x/y labels)
1 parent daa9154 commit 9e12416

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changelog
99
- added methods `subset_results`, `rank_results` to class `AttributeSelection`
1010
(module: `weka.attribute_selection`) to give access to cross-validation
1111
output in numeric rather textual form (NB: it has to parse the textual CV output).
12+
- made the `plot_experiments` method (module `weka.plot.experiments`) more customizable
1213

1314

1415
0.2.12 (2022-12-08)

python/weka/plot/experiments.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
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

1717
import logging
1818
import math
@@ -26,22 +26,28 @@
2626

2727

2828
def 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

Comments
 (0)