PyGObject & Gtk4.0 | Plot is moved out of the grid

Hello,

I am using FigureCanvasGTK4Agg and NavigationToolbar2GTK4 in a Gtk.Box. Following code displays slope percentages on an elevation graph:

distances = PyGraph.pointsDf["distance"]
elevations = PyGraph.pointsDf["elevation"]
slopes = PyGraph.pointsDf["slope"].tail(-1)

path = Path(
    np.array([np.append(distances, distances[::-1]), np.append(elevations, np.zeros_like(elevations))]).T
)
patch = PathPatch(path, facecolor="none")
self._axes.add_patch(patch)

pcolormesh = self._axes.pcolormesh(
    distances,
    [elevations.min(), elevations.max()],
    np.reshape(slopes, (1, len(distances) - 1)),
    cmap=plt.cm.jet,
    clip_path=patch,
    clip_on=True
)

divider = make_axes_locatable(self._axes)
cax = divider.append_axes("right", size="1%", pad=0.1)
self._colorbar = self._figure.colorbar(pcolormesh, cax=cax, label="Slope (%)")

When moving the graph, there is a rendering issue:

When the clip_path parameter is disabled, profile is not displayed and the issue is gone.
If I move the graph totally out of the grid, I am getting the following warning:

/usr/lib/python3.11/site-packages/gi/overrides/Gio.py:42: UserWarning: Tight layout not applied. The bottom and top margins cannot be made large enough to accommodate all Axes decorations.
  return Gio.Application.run(self, *args, **kwargs)

Any help would be appreciated.

Here below a more minimal example without Gtk references:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import PathPatch
from matplotlib.path import Path

fig, ax = plt.subplots()

x = [0, 1, 2, 3]
y = [20, 10, 10, 20]
z = [-10, 0, 10]
z = np.reshape(z, (1, len(x) - 1))

path = np.array([np.array([0, 1, 2, 3, 3, 2, 1, 0]), np.array([20, 10, 10, 20, 0, 0, 0, 0])]).T
patch = PathPatch(Path(path))
ax.add_patch(patch)

im = ax.pcolormesh(
    x,
    [0, np.max(y)],
    z,
    cmap=plt.cm.jet,
    clip_path=patch,
    clip_on=True,
)

fig.tight_layout()
plt.show()

With the same rendering issue (visible out side of the axes):

I just found an easy workaround by adding these two lines afterwards:

im.set_clip_path(patch)
im.set_clip_on(True)

Source: [Bug]: Annotation clip path / box regression in 3.9 · Issue #28717 · matplotlib/matplotlib · GitHub