From aef0fb6954362763e8bdfc239a9a3065f0c4d519 Mon Sep 17 00:00:00 2001 From: Emily Westerbeek Date: Fri, 4 Oct 2024 13:28:57 +0200 Subject: [PATCH 1/6] Added option hide_optimal and corrected index for legenda color --- .../templates/script_get_plot.py.template | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/asreviewcontrib/makita/templates/script_get_plot.py.template b/asreviewcontrib/makita/templates/script_get_plot.py.template index 004ab44..4f4ffbe 100644 --- a/asreviewcontrib/makita/templates/script_get_plot.py.template +++ b/asreviewcontrib/makita/templates/script_get_plot.py.template @@ -26,7 +26,7 @@ from asreview import open_state from asreviewcontrib.insights.plot import plot_recall -def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random): +def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random, hide_optimal): metadata = state.settings_metadata label = None @@ -50,7 +50,10 @@ def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random raise ValueError(f"Invalid legend setting: '{legend_option}'") from err # noqa: E501 if label: - line_index = -2 if not hide_random else -1 + # plot_recall: series is plotted first, than random and optimal, so adjust index + line_index = -3 + if hide_random: line_index += 1 + if hide_optimal: line_index += 1 # add label to line if label not in label_to_line: ax.lines[line_index].set_label(label) @@ -60,7 +63,7 @@ def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random ax.lines[line_index].set_color(label_to_line[label].get_color()) ax.lines[line_index].set_label("_no_legend_") -def get_plot_from_states(states, filename, legend=None, hide_random=False): +def get_plot_from_states(states, filename, legend=None, hide_random=False, hide_optimal=False): """Generate an ASReview plot from state files. Arguments @@ -80,9 +83,9 @@ def get_plot_from_states(states, filename, legend=None, hide_random=False): for state_file in states: with open_state(state_file) as state: - plot_recall(ax, state, show_random = not hide_random) + plot_recall(ax, state, show_random = not hide_random, show_optimal = not hide_optimal) if legend: - _set_legend(ax, state, legend, label_to_line, state_file, hide_random) + _set_legend(ax, state, legend, label_to_line, state_file, hide_random, hide_optimal) if legend: ax.legend(loc=4, prop={"size": 8}) @@ -106,6 +109,11 @@ if __name__ == "__main__": action="store_true", help="Hide the random line.", ) + parser.add_argument( + "--hide_optimal", + action="store_true", + help="Hide the optimal line.", + ) args = parser.parse_args() # load states @@ -116,4 +124,4 @@ if __name__ == "__main__": raise FileNotFoundError(f"No state files found in {args.s}") # generate plot and save results - get_plot_from_states(states, args.o, args.show_legend, args.hide_random) + get_plot_from_states(states, args.o, args.show_legend, args.hide_random, args.hide_optimal) From 70592628fedc3e250d236b61bdddc6a1636bd11b Mon Sep 17 00:00:00 2001 From: Emily Westerbeek Date: Fri, 4 Oct 2024 13:56:39 +0200 Subject: [PATCH 2/6] adhere to style guide --- .../templates/script_get_plot.py.template | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/asreviewcontrib/makita/templates/script_get_plot.py.template b/asreviewcontrib/makita/templates/script_get_plot.py.template index 4f4ffbe..3a4583a 100644 --- a/asreviewcontrib/makita/templates/script_get_plot.py.template +++ b/asreviewcontrib/makita/templates/script_get_plot.py.template @@ -26,7 +26,8 @@ from asreview import open_state from asreviewcontrib.insights.plot import plot_recall -def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random, hide_optimal): +def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random, + hide_optimal): metadata = state.settings_metadata label = None @@ -51,9 +52,7 @@ def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random if label: # plot_recall: series is plotted first, than random and optimal, so adjust index - line_index = -3 - if hide_random: line_index += 1 - if hide_optimal: line_index += 1 + line_index = -3 + hide_random + hide_optimal # add label to line if label not in label_to_line: ax.lines[line_index].set_label(label) @@ -63,7 +62,8 @@ def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random ax.lines[line_index].set_color(label_to_line[label].get_color()) ax.lines[line_index].set_label("_no_legend_") -def get_plot_from_states(states, filename, legend=None, hide_random=False, hide_optimal=False): +def get_plot_from_states(states, filename, legend=None, hide_random=False, + hide_optimal=False): """Generate an ASReview plot from state files. Arguments @@ -83,9 +83,11 @@ def get_plot_from_states(states, filename, legend=None, hide_random=False, hide_ for state_file in states: with open_state(state_file) as state: - plot_recall(ax, state, show_random = not hide_random, show_optimal = not hide_optimal) + plot_recall(ax, state, show_random = not hide_random, + show_optimal = not hide_optimal) if legend: - _set_legend(ax, state, legend, label_to_line, state_file, hide_random, hide_optimal) + _set_legend(ax, state, legend, label_to_line, state_file, + hide_random, hide_optimal) if legend: ax.legend(loc=4, prop={"size": 8}) @@ -124,4 +126,5 @@ if __name__ == "__main__": raise FileNotFoundError(f"No state files found in {args.s}") # generate plot and save results - get_plot_from_states(states, args.o, args.show_legend, args.hide_random, args.hide_optimal) + get_plot_from_states(states, args.o, args.show_legend, args.hide_random, + args.hide_optimal) From c4790a23cb1ef41180cb8c02255b03e4202401d8 Mon Sep 17 00:00:00 2001 From: Rens van de schoot Date: Mon, 7 Oct 2024 13:16:54 +0200 Subject: [PATCH 3/6] Add Insights v1.3 as dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b8ae1a8..23b3ae6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ classifiers = [ "Programming Language :: Python :: 3.12" ] license = {text = "MIT"} -dependencies = ["asreview>=1.3,<2", "jinja2", "cfgtemplater"] +dependencies = ["asreview>=1.3,<2", "asreview-insights>=1.3", "jinja2", "cfgtemplater"] dynamic = ["version"] requires-python = ">=3.7" From c8a8c4ee1a3516764eb54df8bdd4afd185b311b0 Mon Sep 17 00:00:00 2001 From: Rens van de schoot Date: Wed, 16 Oct 2024 08:48:50 +0200 Subject: [PATCH 4/6] Revert adding dependency on insights in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 23b3ae6..b8ae1a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ classifiers = [ "Programming Language :: Python :: 3.12" ] license = {text = "MIT"} -dependencies = ["asreview>=1.3,<2", "asreview-insights>=1.3", "jinja2", "cfgtemplater"] +dependencies = ["asreview>=1.3,<2", "jinja2", "cfgtemplater"] dynamic = ["version"] requires-python = ">=3.7" From f262a30d9374feb57aedbcbfab9c76c1f4163dc7 Mon Sep 17 00:00:00 2001 From: Rens van de schoot Date: Wed, 16 Oct 2024 08:50:24 +0200 Subject: [PATCH 5/6] Add dependency insights 1.3 to doc_README.md.template --- asreviewcontrib/makita/templates/doc_README.md.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asreviewcontrib/makita/templates/doc_README.md.template b/asreviewcontrib/makita/templates/doc_README.md.template index afdb93e..cd74724 100644 --- a/asreviewcontrib/makita/templates/doc_README.md.template +++ b/asreviewcontrib/makita/templates/doc_README.md.template @@ -11,7 +11,7 @@ The template is described as: '{{ template_name_long }}'. This project depends on Python 3.7 or later (python.org/download), and [ASReview](https://asreview.nl/download/). Install the following dependencies to run the simulation and analysis in this project. ```sh -pip install asreview>=1.0 asreview-insights>=1.1.2 asreview-datatools +pip install asreview>=1.0 asreview-insights>=1.3 asreview-datatools ``` {% if not skip_wordclouds %} For generating wordclouds, install the following dependencies. From b504575c8865d2a0c073c4570dd2b34d36529d7f Mon Sep 17 00:00:00 2001 From: Jelle Teijema Date: Thu, 7 Nov 2024 10:49:19 +0100 Subject: [PATCH 6/6] Update asreviewcontrib/makita/templates/script_get_plot.py.template Co-authored-by: Timo van der Kuil <5330531+timovdk@users.noreply.github.com> --- asreviewcontrib/makita/templates/script_get_plot.py.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asreviewcontrib/makita/templates/script_get_plot.py.template b/asreviewcontrib/makita/templates/script_get_plot.py.template index 3a4583a..fc2a7c4 100644 --- a/asreviewcontrib/makita/templates/script_get_plot.py.template +++ b/asreviewcontrib/makita/templates/script_get_plot.py.template @@ -51,7 +51,7 @@ def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random raise ValueError(f"Invalid legend setting: '{legend_option}'") from err # noqa: E501 if label: - # plot_recall: series is plotted first, than random and optimal, so adjust index + # plot_recall: series is plotted first, then random and optimal, so adjust index line_index = -3 + hide_random + hide_optimal # add label to line if label not in label_to_line: