diff --git a/dnotebooks/plots/plots.py b/dnotebooks/plots/plots.py index c855258..69f6371 100644 --- a/dnotebooks/plots/plots.py +++ b/dnotebooks/plots/plots.py @@ -24,7 +24,7 @@ ExperimentPartitions, ) -from dnotebooks.utils import RegexColorDict +from dnotebooks.utils import RegexColorDict, LineStyle from .confusion_matrix_utils import ( get_n_hop_normalized_confusion_matrices_mean, @@ -724,7 +724,7 @@ def draw(self): max_time = max(max_time) if len(max_time) > 0 else None for label, seeds_confusion_matrices in self.confusion_matrices.items(): - linestyle = self._linestyles[label] + linestyle = LineStyle.resolve(self._linestyles[label]).to_kwargs() c = self._custom_colors.get(label) Y = stack_mean_node_metric( seeds_confusion_matrices, @@ -763,7 +763,7 @@ def draw(self): self.epoch[0], self.epoch[1] )[:len(Y)] self._ax.fill_between(X, Y_lower_bound, Y_upper_bound, color=c, alpha=.3) - self._ax.plot(X, Y, color=c, label=label, alpha=1, linestyle=linestyle) + self._ax.plot(X, Y, color=c, label=label, alpha=1, **linestyle) if self.ylimit: self._ax.set_ylim(ymin=self.ylimit[0], ymax=self.ylimit[1]) diff --git a/dnotebooks/utils.py b/dnotebooks/utils.py index 75eae00..68a8e56 100644 --- a/dnotebooks/utils.py +++ b/dnotebooks/utils.py @@ -1,8 +1,11 @@ +from __future__ import annotations + from typing import Optional, Dict import re from pathlib import Path import yaml import hashlib +from dataclasses import dataclass def _string_to_color(s: str) -> str: @@ -46,3 +49,34 @@ def get(self, key: str) -> str: if self.default: return self.default return _string_to_color(key) + + +@dataclass +class LineStyle: + DEFAULT = 'solid' + STYLE_OPTIONS = [ + 'solid', + 'dashed', + 'dotted', + '*', + 'o', + 's', + 'D' + ] + + linestyle: Optional[str] = None + marker: Optional[str] = None + + def to_kwargs(self): + return { + "marker": self.marker, + "linestyle": self.linestyle, + "markevery": .2, + "markerfacecolor": 'white' + } + + @staticmethod + def resolve(label: Optional[str]) -> LineStyle: + if label in ['*', 'o', 's', 'D']: + return LineStyle('solid', label) + return LineStyle(label, None) diff --git a/dnotebooks/widgets/selection.py b/dnotebooks/widgets/selection.py index 7897765..79f9ab2 100644 --- a/dnotebooks/widgets/selection.py +++ b/dnotebooks/widgets/selection.py @@ -19,7 +19,8 @@ ExperimentConfusionMatrix, ExperimentConfusionMatrixDelta ) -from dnotebooks.utils import RegexColorDict +from dnotebooks.utils import RegexColorDict, LineStyle + from .miscellaneous import LabelPP, MultiCheckboxWidget, MultiCheckboxWithLimitWidget @@ -83,7 +84,6 @@ def _load_experiment_group(root: Path) -> Dict[str, ExperimentGroup]: def StyledExperimentSelectionWidget( root: Path = Path("."), limit: Optional[int] = None, - style_options: Optional[List[str]] = None, ) -> Tuple[VBox, Callable[[], List[Tuple[ExperimentGroup, str]]]]: """ Multi-experiment selection widget with style dropdown per experiment. @@ -97,9 +97,6 @@ def StyledExperimentSelectionWidget( Tuple of (widget, getter_function) - getter_function returns List[Tuple[Path, style]] ordered by selection time """ - if style_options is None: - style_options = ['solid', 'dashed', 'dotted', '*', 'o', 's', 'D'] - # Track experiments and their widgets experiment_rows: Dict[str, Tuple[ExperimentGroup, HBox, Checkbox, Dropdown]] = {} selection_order: OrderedDict[str, int] = OrderedDict() # name -> selection_timestamp @@ -116,8 +113,8 @@ def _create_experiment_row(name: str, experiment_group: ExperimentGroup) -> Tupl ) count_label = Label(f"({len(experiment_group.paths)} files)", layout=Layout(width='100px')) style_dropdown = Dropdown( - options=style_options, - value=style_options[0], + options=LineStyle.STYLE_OPTIONS, + value=LineStyle.DEFAULT, layout=Layout(width='150px'), disabled=True # Disabled until checkbox is selected )