#!/usr/bin/env python3
import os
import sys

# 1) force GTK3 backend *before* pyplot is imported
os.environ['MPLBACKEND'] = 'GTK3Agg'   # or GTK3Cairo

# 2) turn on every debug message GLib/GTK will give us
os.environ['G_MESSAGES_DEBUG'] = 'all'
os.environ['GTK_DEBUG'] = 'interactive'   # also enables Ctrl-Shift-I inspector

import matplotlib
matplotlib.use('GTK3Agg')          # belt-and-braces: make sure
import matplotlib.pyplot as plt

print('GTK3Agg backend loaded, creating figure…')
fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1])
ax.set_title('GTK3-Matplotlib window – close it to finish')
print('Showing figure…')
plt.show()
print('plt.show() returned – script ends')

