Skip to content

Commit

Permalink
fix: hack around color problem in itermplot (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Mar 17, 2022
1 parent c07d1df commit 6484b36
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/uproot_browser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from __future__ import annotations

import asyncio
import functools
import os
from pathlib import Path
from typing import Any
from typing import Any, Callable

import click
import rich
Expand All @@ -34,6 +35,20 @@ def tree(filename: str) -> None:
uproot_browser.tree.print_tree(filename)


def intercept(func: Callable[..., Any], *names: str) -> Callable[..., Any]:
"""
Intercept function arguments and remove them
"""

@functools.wraps(func)
def new_func(*args: Any, **kwargs: Any) -> Any:
for name in names:
kwargs.pop(name)
return func(*args, **kwargs)

return new_func


@main.command()
@click.argument("filename")
@click.option(
Expand Down Expand Up @@ -61,6 +76,13 @@ def plot(filename: str, iterm: bool) -> None:

if iterm:
uproot_browser.plot_mpl.plot(item)
if plt.get_backend() == r"module://itermplot":
fm = plt.get_current_fig_manager()
canvas = fm.canvas
canvas.__class__.print_figure = intercept(
canvas.__class__.print_figure, "facecolor", "edgecolor"
)

plt.show()
else:
uproot_browser.plot.clf()
Expand Down

0 comments on commit 6484b36

Please sign in to comment.