Bonsoir,

Le gars sur

réalise un code où il lance la visualisation d'un graphe matplotlib depuis une fenêtre tkinter.. et ça fonctionne.

j'ai une code où la visualisation d'un graph matplotlib est également lancée depuis une fonction.
Tant qu'il n'y avait pas de GUI tkinter ça fonctionnait et mon graphe apparaissait dans la fenêtre matplotlib.

j'ai ajouté une GUI tk et maintenant la fenêtre du graphe s'ouvre mais reste noire et le graphe n’apparaît qu'au moment où je ferme la fenêtre tk.

Y aurait-il un truc a savoir pour éviter ce conflit et retrouver un comportement aussi simple et naturel que celui sur la vidéo?

PS: Voici un bout de code qui reproduit mon problème (du moins chez moi, sur un notebook jupyter).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
%matplotlib qt 
# pour afficher la fenetre matplotlib depuis un notebook jupyter 
 
from tkinter import *
import numpy as np # faire des matrices utilisable pour les graphes
import matplotlib.pyplot as plt # pour faire des graphes
from mpl_toolkits.mplot3d import Axes3D # faire des graphes 3D
 
def sampling_checks(x):
    global cpt, col_idx
    for i, param in enumerate(par_list):
        if v[x].get() == param and cpt < 3:
            col_idx[cpt] = i
            cpt += 1
            if cpt == 3:
                sampling_3Dplot(col_idx[0], col_idx[1], col_idx[2], colList, par_list)
 
def sampling_3Dplot(col0, col1, col2, columns, params):
    X = columns[col0] 
    Y = columns[col1] 
    Z = columns[col2]
    ax = plt.axes(projection='3d')
    ax.set_xlabel(params[col0])
    ax.set_ylabel(params[col1])
    ax.set_zlabel(params[col2])
    ax.scatter(X,Y,Z) 
    plt.show() 
 
 
fen = Tk()
 
par_list = ["temp", "time", "cata", "equiv"]
colList = [[1,2,3,4,5,],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]]
cpt=0
col_idx = [None, None, None]
v = [None] * len(par_list)
for i, param in enumerate(par_list):
    v[i] = StringVar()
    c0 = Checkbutton(fen, text=param, variable=v[i], onvalue=param, offvalue='', 
                     command=lambda x=i: sampling_checks(x))
    c0.grid(column=i, row=0, padx=2, pady=5) 
 
fen.mainloop()