daleroberts / itermplot

An awesome iTerm2 backend for Matplotlib, so you can plot directly in your terminal.
1.49k stars 51 forks source link

Suggestion: set style with env var, and allow turning transparency off #35

Open z0u opened 5 years ago

z0u commented 5 years ago

I've been trying to work around #33 by styling the background of the axes, but I now see that the figure is being forced to be transparent. It would be nice if there was a way to disable that.

More generally: Would it be feasible/sensible to use stylesheets instead of reversing the video? I.e, have an environment variable that takes a stylesheet name and overrides the colours based on that?

henryiii commented 2 years ago

Running into this too with https://github.com/henryiii/uproot-browser/issues/33. Hardcoding forcing of this to transparent and wiping the face color makes it impossible to use on black terminals (or if you themed it white, then on white terminals). Shouldn't the face color part be removed, then just the transparent=True would remain (fine), letting users pick a background color or no color?

henryiii commented 2 years ago

Here's my hacky workaround:

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

if plt.get_backend() == r"module://itermplot":
    fm = plt.get_current_fig_manager()
    canvas = fm.canvas
    # Ideally this should only runs once
    canvas.__class__.print_figure = intercept(
        canvas.__class__.print_figure, "facecolor", "edgecolor"
    )

plt.show()