You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to save figure with GTK4 on Mac, the file format is always pgf regardless what we have selected. Furthermore, if the saving pgf fails, an error box is displayed and cannot be closed. I tried to investigate what was happening there but haven't fixed it yet. (See additional information)
No matter what we have selected, format is always pgf when saving
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltimportmatplotlibasmplprint(mpl.__file__)
print(mpl.__version__)
mpl.use('gtk4agg')
# evenly sampled time at 200ms intervalst=np.arange(0., 5., 0.2)
# red dashes, blue squares and green trianglesplt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
However, after fixing this, it always resolve to PNG (the correct default choice.) I suspect dialog.add_choice() cannot work correctly on Mac or doesn't work anymore.
The easiest fix is extracting the file extension via dialog.get_file() which is already at line 372 in /lib/matplotlib/backends/backend_gtk4.py line 361
Today I tested GTK 3 and GTK 4 on Ubuntu. GTK3 works well. GTK4 works well and the "always default" bug doesn't occur as on Mac. So the bug that file filter doesn't work may be a Mac only bug. Also, the different behavior on different platforms make the bug hard to fix:
Above, I suggested. extracting the file extension with dialog.get_file(). However, the file name retrieved from dialog.get_file() wasn't automatically set with the selected extension format - the behavior of getting file name on Ubuntu and on Mac is different. (See P. S. for more detailed description)
Furthermore, the GTK4 documentation doesn't state that what kind of behavior is expected or guaranteed. Thus, the solution proposed above about extracting the file extension with dialog.get_file() won't guarantee portability.
P.S.
Example using GTK4:
With GTK4, after we select SVG format from the filter, the file name won't be updated with the format we selected. We have to manually edit the file name before clicking "Save"
Example using Mac:
With Mac, the default file name displayed in the text input box for user is without an extension - e.g., "Figure_1". After clicking save, the app will add the extension for us - dialog.get_file().get_path() will give something like "Figure_1.png"
Bug summary
When trying to save figure with GTK4 on Mac, the file format is always pgf regardless what we have selected. Furthermore, if the saving pgf fails, an error box is displayed and cannot be closed. I tried to investigate what was happening there but haven't fixed it yet. (See additional information)
No matter what we have selected, format is always pgf when saving

Code for reproduction
Actual outcome
Save fig fails
Expected outcome
Save fig success
Additional information
pygobject 3.44.1
gtk4: stable 4.12.0
For the "always pgf" bug:
/lib/matplotlib/backends/backend_gtk4.py line 361
should be
full code snippet:
dialog
is a Gtk.FileChooserNative instance.However, after fixing this, it always resolve to PNG (the correct default choice.) I suspect
dialog.add_choice()
cannot work correctly on Mac or doesn't work anymore.The easiest fix is extracting the file extension via
dialog.get_file()
which is already at line 372 in /lib/matplotlib/backends/backend_gtk4.py line 361P. S.
I tried to replace it with
Gtk.FileChooserNative.get_filter()
, but it doesn't work and it's probably a confirmed bug in GTK4https://gitlab.gnome.org/GNOME/gtk/-/issues/1820Operating system
Mac
Matplotlib Version
3.8.0.dev1829+g3d2d0727ec.d20230818
Matplotlib Backend
gtk4agg
Python version
3.9.6
Jupyter version
No response
Installation
None
The text was updated successfully, but these errors were encountered: