Skip to content

[Bug]: Any operation on matplotlib fails due to gtk4 backend error #25602

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

Closed
mikayahlevi opened this issue Apr 2, 2023 · 3 comments
Closed
Labels
Milestone

Comments

@mikayahlevi
Copy link

mikayahlevi commented Apr 2, 2023

Bug summary

This may be an Arch Linux dependency issue, but when using GTK4 as the backend any operation that involves a window will crash the Python program.

Code for reproduction

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

Actual outcome

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 1450, in subplots
    fig = figure(**fig_kw)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 783, in figure
    manager = new_figure_manager(
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/pyplot.py", line 359, in new_figure_manager
    return _get_backend_mod().new_figure_manager(*args, **kwargs)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 3513, in new_figure_manager
    return cls.new_figure_manager_given_figure(num, fig)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 3518, in new_figure_manager_given_figure
    return cls.FigureCanvas.new_manager(figure, num)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 1703, in new_manager
    return cls.manager_class.create_with_canvas(cls, figure, num)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2830, in create_with_canvas
    return cls(canvas_class(figure), num)
  File "/home/mikayah/.local/lib/python3.10/site-packages/matplotlib/backends/backend_gtk4.py", line 79, in __init__
    **css.load_from_data(b".matplotlib-canvas { background-color: white; }")
TypeError: Gtk.CssProvider.load_from_data() takes exactly 3 arguments (2 given)**

Expected outcome

Not crashing

Additional information

No response

Operating system

Arch

Matplotlib Version

3.6.3

Matplotlib Backend

GTK4Agg

Python version

3.10.10

Jupyter version

No response

Installation

Linux package manager

@oscargus
Copy link
Member

oscargus commented Apr 3, 2023

Strange. I am in no way an expert on this, but did a quick search and in the C/C++ interface load_from_data takes another argument, the length of the "string" (byte-sequence). However, the Python binding only takes the "string": https://amolenaar.github.io/pgi-docgen/#Gtk-4.0/classes/CssProvider.html#Gtk.CssProvider.load_from_data

@oscargus
Copy link
Member

oscargus commented Apr 3, 2023

On the other hand there was a fix in #25280 that seems very related. This was merged into 3.7.1, so if you get hold of the latest Matplotlib version, it should work!(?)

if Gtk.check_version(4, 9, 3) is None:
css.load_from_data(style, -1)
else:
css.load_from_data(style.encode('utf-8'))

@ksunden
Copy link
Member

ksunden commented Apr 3, 2023

Given this does appear to be addressed on main (and even a release) already, as @oscargus points out, I'll go ahead and close this, feel free to re-ping us/reopen if that does not actually address the issue.

@ksunden ksunden closed this as completed Apr 3, 2023
@QuLogic QuLogic added this to the v3.7.1 milestone Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants