Skip to content

Commit

Permalink
Add option hide_optimal and correct index for legenda color (#66)
Browse files Browse the repository at this point in the history
* Added option hide_optimal and corrected index for legenda color

* Add Insights v1.3 as dependency

---------

Co-authored-by: Rens van de schoot <[email protected]>
Co-authored-by: Jelle Teijema <[email protected]>
Co-authored-by: Timo van der Kuil <[email protected]>
  • Loading branch information
4 people authored Nov 7, 2024
1 parent c002482 commit b5cefd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion asreviewcontrib/makita/templates/doc_README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 17 additions & 6 deletions asreviewcontrib/makita/templates/script_get_plot.py.template
Original file line number Diff line number Diff line change
Expand Up @@ -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):
def _set_legend(ax, state, legend_option, label_to_line, state_file, hide_random,
hide_optimal):
metadata = state.settings_metadata
label = None

Expand All @@ -50,7 +51,8 @@ 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, 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:
ax.lines[line_index].set_label(label)
Expand All @@ -60,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):
def get_plot_from_states(states, filename, legend=None, hide_random=False,
hide_optimal=False):
"""Generate an ASReview plot from state files.

Arguments
Expand All @@ -80,9 +83,11 @@ 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})
Expand All @@ -106,6 +111,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
Expand All @@ -116,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)
get_plot_from_states(states, args.o, args.show_legend, args.hide_random,
args.hide_optimal)

0 comments on commit b5cefd6

Please sign in to comment.