Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hack around color problem in itermplot #35

Merged
merged 1 commit into from
Mar 17, 2022
Merged
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
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