Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option hide_optimal and correct index for legenda color #66

Merged
merged 7 commits into from
Nov 7, 2024
Merged
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)