Embed in GTK4 with a navigation toolbar
NavigationToolbar2GTK4
as
NavigationToolbar
from
matplotlib.backends.backend_gtk4agg
import
FigureCanvasGTK4Agg
as
FigureCanvas
from
matplotlib.figure
import
def
on_activate
(
app
):
win
=
Gtk
.
ApplicationWindow
(
application
=
app
)
win
.
set_default_size
(
400
,
300
)
win
.
set_title
(
"Embedded in GTK4"
)
fig
=
(
figsize
=
(
5
,
4
),
dpi
=
100
)
ax
=
fig
.
add_subplot
(
1
,
1
,
1
)
t
=
(
0.0
,
3.0
,
0.01
)
s
=
(
2
*
*
t
)
ax
.
plot
(
t
,
s
)
vbox
=
Gtk
.
Box
(
orientation
=
Gtk
.
Orientation
.
VERTICAL
)
win
.
set_child
(
vbox
)
canvas
=
FigureCanvas
(
fig
)
canvas
.
set_hexpand
(
True
)
canvas
.
set_vexpand
(
True
)
vbox
.
append
(
canvas
)
toolbar
=
NavigationToolbar
(
canvas
)
vbox
.
append
(
toolbar
)
win
.
present
()
app
=
Gtk
.
Application
(
application_id
=
'org.matplotlib.examples.EmbeddingInGTK4PanZoom'
)
app
.
connect
(
'activate'
,
on_activate
)
app
.
run
(
None
)