jktr / matplotlib-backend-kitty

show matplotlib plots directly in your kitty terminal
Creative Commons Zero v1.0 Universal
137 stars 16 forks source link

Appears as a non-GUI backend with `matplotlib==3.6.0` #6

Closed Sibgatulin closed 1 year ago

Sibgatulin commented 1 year ago

Firstly, thanks for the module, it has been hugely helpful for me on daily basis!

Secondly, calling plt.show() with matplotlib==3.6.0 (specifically matplotlib-3.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl) release results in

UserWarning: Matplotlib is currently using module://matplotlib-backend-kitty, which is a non-GUI backend, so cannot show the figure.
  _Backend.show(*args, **kwargs)

(same goes for matplotlib-backend-notcurses, btw).

I am, unfortunately, at a loss, if I am simply missing something. Please let me know if I can help with more information.

jktr commented 1 year ago

Firstly, thanks for the module, it has been hugely helpful for me on daily basis!

I'm glad to hear that.

Secondly, calling plt.show() with matplotlib==3.6.0 (specifically matplotlib-3.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl) release results in

UserWarning: Matplotlib is currently using module://matplotlib-backend-kitty, which is a non-GUI backend, so cannot show the figure.
  _Backend.show(*args, **kwargs)

(same goes for matplotlib-backend-notcurses, btw).

Thanks for the report. Looks like MPL changed how plugins are initialized. This is prabably an easy fix; I'll take a look at it over the weekend.

haininhhoang94 commented 1 year ago

How it is going? Thanks!

min-xu-ai commented 1 year ago

I downgraded to 3.4.3, this lib is working for me. With latest version, it seems that FigureManagerICat just didn't get registered with matplotlib.

joemilbourn commented 1 year ago

I think that FigureManager.manager_class isn't getting set to FigureManagerICat, so drawing the figure happens with the default manager for FigureCanvasAgg, which is non-GUI.

Probably not the right way of doing things, but setting the manager class manually in _BackendICatAgg seems to work. Something like:

class _BackendICatAgg(_Backend):
    FigureCanvas = FigureCanvasAgg
    FigureManager = FigureManagerICat
    FigureCanvas.manager_class = FigureManager

@jktr Thank you for matlotlib-backend-kitty, which I use almost every day.

jktr commented 1 year ago

Thanks, @joemilbourn. This seems to have been the underlying issue. I've pushed a proposed fix to the fix/mpl-3.6 branch. It'd be great if you could verify that that fixes it for you.

joemilbourn commented 1 year ago

That works, thank you!

eo1989 commented 1 year ago

Just wanted to chime in that I also receive this error using mpl-3.5.3. Would the mpl-3.6.0 branch work on 3.5.3 by chance?

Edit: After pip installing the fix/mpl-3.6.0 branch I was able to quickly plot in kitty using the example in the readme using mpl 3.5.3!!

jktr commented 1 year ago

The fix is live. Thanks for your patience.