Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dnotebooks/plots/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down
34 changes: 34 additions & 0 deletions dnotebooks/utils.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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)
11 changes: 4 additions & 7 deletions dnotebooks/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
ExperimentConfusionMatrix,
ExperimentConfusionMatrixDelta
)
from dnotebooks.utils import RegexColorDict
from dnotebooks.utils import RegexColorDict, LineStyle

from .miscellaneous import LabelPP, MultiCheckboxWidget, MultiCheckboxWithLimitWidget


Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
)
Expand Down
Loading