Skip to content

Commit

Permalink
hacking toward display revisions, not yet finished but want to test o…
Browse files Browse the repository at this point in the history
…n old builds before moving forward
  • Loading branch information
bmcfee committed Apr 1, 2024
1 parent ca6d7b2 commit b8a9396
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
34 changes: 20 additions & 14 deletions mir_eval/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,21 @@ def segments(
if height is None:
height = ax.get_ylim()[1]

cycler = ax._get_patches_for_fill.prop_cycler
#cycler = ax._get_patches_for_fill.prop_cycler

seg_map = dict()

for lab in labels:
if lab in seg_map:
continue

style = next(cycler)
#style = next(cycler)
_bar = ax.bar([0], [0], visible=False)
style = {k: v for k, v in _bar[0].properties().items() if k in ["facecolor", "edgecolor", "linewidth"]}
_bar.remove()
seg_map[lab] = seg_def_style.copy()
seg_map[lab].update(style)
# Swap color -> facecolor here so we preserve edgecolor on rects
seg_map[lab]["facecolor"] = seg_map[lab].pop("color")
seg_map[lab].update(kwargs)
seg_map[lab]["label"] = lab

Expand Down Expand Up @@ -278,9 +280,10 @@ def labeled_intervals(

style = dict(linewidth=1)

style.update(next(ax._get_patches_for_fill.prop_cycler))
# Swap color -> facecolor here so we preserve edgecolor on rects
style["facecolor"] = style.pop("color")
_bar = ax.bar([0], [0], visible=False)
style.update(facecolor=_bar.patches[0].get_facecolor())
_bar.remove()
style.update(kwargs)

if base is None:
Expand Down Expand Up @@ -391,7 +394,8 @@ def hierarchy(intervals_hier, labels_hier, levels=None, ax=None, **kwargs):

# Reverse the patch ordering for anything we've added.
# This way, intervals are listed in the legend from top to bottom
ax.patches[n_patches:] = ax.patches[n_patches:][::-1]
# FIXME: this no longer works
#ax.patches[n_patches:] = ax.patches[n_patches:][::-1]
return ax


Expand Down Expand Up @@ -458,10 +462,11 @@ def events(times, labels=None, base=None, height=None, ax=None, text_kw=None, **
if height is None:
height = ax.get_ylim()[1]

cycler = ax._get_patches_for_fill.prop_cycler

style = next(cycler).copy()
_plot = ax.plot([], [], visible=False)[0]
style = {k: v for k, v in _plot.properties().items() if k in ["color", "linestyle", "linewidth"]}
_plot.remove()
style.update(kwargs)

# If the user provided 'colors', don't override it with 'color'
if "colors" in style:
style.pop("color", None)
Expand Down Expand Up @@ -772,7 +777,12 @@ def separation(sources, fs=22050, labels=None, alpha=0.75, ax=None, **kwargs):
# For each source, grab a new color from the cycler
# Then construct a colormap that interpolates from
# [transparent white -> new color]
color = next(ax._get_lines.prop_cycler)["color"]
#
# To access the cycler, we'll create a temporary bar plot,
# pull its facecolor, and then remove it from the axes.
_bar = ax.bar([0], [0], visible=False)
color = _bar.patches[0].get_facecolor()
_bar.remove()
color = color_conv.to_rgba(color, alpha=alpha)
cmap = LinearSegmentedColormap.from_list(
labels[i], [(1.0, 1.0, 1.0, 0.0), color]
Expand All @@ -788,10 +798,6 @@ def separation(sources, fs=22050, labels=None, alpha=0.75, ax=None, **kwargs):
label=labels[i],
)

# Attach a 0x0 rect to the axis with the corresponding label
# This way, it will show up in the legend
ax.add_patch(Rectangle((0, 0), 0, 0, color=color, label=labels[i]))

if new_axes:
ax.axis("tight")

Expand Down
6 changes: 3 additions & 3 deletions tests/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from mir_eval.io import load_wav


pytestmark = pytest.mark.skip(
reason="disabling display tests until after merger of #370"
)
#pytestmark = pytest.mark.skip(
# reason="disabling display tests until after merger of #370"
#)


@decorator
Expand Down

0 comments on commit b8a9396

Please sign in to comment.