asreview-insights
asreview-insights copied to clipboard
Plotting multiple statefiles dynamically.
The example for the new multiple plots code is as follows:
import matplotlib.pyplot as plt
from asreview import open_state
from asreviewcontrib.insights.plot import plot_recall
fig, ax = plt.subplots()
with open_state("tests/asreview_files/sim_van_de_schoot_2017_1.asreview") as s1:
with open_state("tests/asreview_files/"
"sim_van_de_schoot_2017_logistic.asreview") as s2:
plot_recall(ax,
[s1, s2],
legend_values=["Naive Bayes", "Logistic"],
legend_kwargs={'loc': 'lower center'})
fig.savefig("docs/example_multiple_lines.png")
However, how would one do this dynamically? open_state() method is returning a '_GeneratorContextManager' object, which implies that it is intended to be used as a context manager with the with statement. However, I can't dynamically open a cascading with statement, and I can't store the state for later using:
for state_file in states:
state = open_state(state_file)
state_objs.append(state)
plot_recall(ax, state_objs, **plot_kwargs)
Any advise for this implementation? I think I cannot manually manage the lifetime of the state objects and they must be used within a with block, and thus I am forced to call plot_recall separately.
Interesting question. It would be easier if the state class had an open and close method similar to Python's open
. We have .close()
, but .open()
might be useful as well.
For your application, did you try:
https://github.com/asreview/asreview-insights/blob/873c93fe6fb998d071351586f6ffc85b4518ce67/asreviewcontrib/insights/utils.py#L45-L60
You can copy how the entrypoint does it, indeed using _iter_states
. If we actually use _iter_states
in one of the examples, we should make it public though. Also, I guess the docstring of the various plot functions could be improved, to say (generator of) asreview.state.SQLiteState
instead of (list of) asreview.state.SQLiteState
.