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
Hi
I try to embed sympy plot in a GTK4 window. This is my code:
importgigi.require_version('Gtk', '4.0')
fromgi.repositoryimportGtkfrommatplotlib.backends.backend_gtk4aggimport (
FigureCanvasGTK4AggasFigureCanvas)
frommatplotlib.figureimportFigureimportnumpyasnpfromsympyimport*defon_activate(app):
win=Gtk.ApplicationWindow(application=app)
win.set_default_size(400, 300)
win.set_title("Embedding in GTK4")
x=symbols("x")
f=x**2+3*x-5fig=plot(f)._backend.fig# A scrolled margin goes outside the scrollbars and viewport.sw=Gtk.ScrolledWindow(margin_top=10, margin_bottom=10,
margin_start=10, margin_end=10)
win.set_child(sw)
canvas=FigureCanvas(fig) # a Gtk.DrawingAreacanvas.set_size_request(800, 600)
sw.set_child(canvas)
win.show()
app=Gtk.Application(application_id='org.matplotlib.examples.EmbeddingInGTK4')
app.connect('activate', on_activate)
app.run(None)
The problem is that after running the program, it show a window of plot, then after closing that window, the GTK window with embedded plot shown. And if i set show=False, this error shown:
Traceback (most recent call last):
File "/home/mskf1383/سندها/پروژهها/python_projects/GTK/mplot.py", line 19, in on_activate
fig = plot(f, show=False)._backend.fig
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Plot' object has no attribute '_backend'. Did you mean: 'backend'?
And if I remove ._backend.fig (fig = plot(f, show=False)), this error shown:
Traceback (most recent call last):
File "/home/mskf1383/سندها/پروژهها/python_projects/GTK/mplot.py", line 26, in on_activate
canvas = FigureCanvas(fig) # a Gtk.DrawingArea
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk4.py", line 42, in __init__
super().__init__(figure=figure)
File "/usr/lib/python3/dist-packages/matplotlib/backend_bases.py", line 1643, in __init__
figure.set_canvas(self)
^^^^^^^^^^^^^^^^^
AttributeError: 'Plot' object has no attribute 'set_canvas'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
I try to embed sympy plot in a GTK4 window. This is my code:
The problem is that after running the program, it show a window of plot, then after closing that window, the GTK window with embedded plot shown. And if i set
show=False
, this error shown:And if I remove
._backend.fig
(fig = plot(f, show=False)
), this error shown:How can I fix that?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions