IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Matplotlib - Slider


Sujet :

Tkinter Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    manutentionnaire
    Inscrit en
    Décembre 2020
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : manutentionnaire

    Informations forums :
    Inscription : Décembre 2020
    Messages : 31
    Points : 13
    Points
    13
    Par défaut Matplotlib - Slider
    bonjour à tous,

    je souhaite poser une slider pour un défilement sur l'axe X
    Le slider est en place, mais je n'arrive pas à accéder par la souris
    quelqu'un à une expérience sur ce cas.
    merci d'avance de votre aide
    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
     
    # coding:utf-8
    #version 3.x python
     
    # ==================================================
    #                                         ID python 3.7.2
    # ==================================================
    from tkinter import *
    import tkinter as tk
    from tkinter import ttk
    print("TkVersion", TkVersion)
    print("TclVersion", TclVersion)
    print("Python version", sys.version_info)
    import sys; print('Python %s on %s' % (sys.version, sys.platform))
     
    # ==================================================
    #                                         matplotlib 3.3.3
    # ==================================================
    from pylab import *                                                                                            # importe tout de matplotlib
    import matplotlib.pyplot as plt
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredAuxTransformBox
    from matplotlib.widgets import Slider
     
    print("MatPlotLib version : ", matplotlib.__version__)
    print('MatPlotLib version : {}'.format(matplotlib.__version__))
     
    # ==================================================
    #                                  Notebook - Hauteur Largeur
    # ==================================================
    def _on_tab_changed(event):
    	print("\n")
    	'''
            update_idletasks
            Python est tkinter peuvent "mettre en sommeil" (idle) certaines tâches d'affichage, non essentielles, par exemple
            le redimensionnement des contrôles. Ces mises à jour de l'affichage sont dîtes dormantes. Pour forcer la mise à jour
            d'un tel affichage, utilisez .update_idletasks ( ) sans attendre la fin du traitement des gestionnaires d’événement et son retour au début de la boucle principale.
            '''
     
    	nb = event.widget
    	nb.update_idletasks()
     
    	tab = nb.nametowidget(nb.select())
     
    	nb.configure(height=tab.winfo_reqheight())														# Dimensionnement Hauteur
    	nb.configure(width=tab.winfo_reqwidth())													    # Dimensionnement Largeur
     
     
    def Create_notebook(master=None, **kw):
    	nb = ttk.Notebook(master, **kw)
    	nb.bind("<<NotebookTabChanged>>", _on_tab_changed)
    	return nb
     
    # ==================================================
    #                                  Fenêtre Principal - Configuration
    # ==================================================
    root = tk.Tk()                                                                                                    # Crée une instance Tk class
    root.title("Titre")
    root.resizable(False, False)                                                                                 # Fenêtre verrouillée
     
    window_height = 800
    window_width = 900
     
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
     
    x_cordinate = int((screen_width/2) - (window_width/2))
    y_cordinate = int((screen_height/2) - (window_height/2))
     
    root.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
     
    # ==================================================
    #                                  Frames
    # ==================================================
     
    # --- Frame gauche ---
    RightFrame = tk.LabelFrame(root, text="[Label]", font=('verdana', 8, ''), foreground="blue", relief=SOLID, borderwidth=0)
    RightFrame.place(x=130, y=5, width=900, height=900)
    RightFrame.anchor(anchor="center")
     
    # Notebook
    notebook = Create_notebook(RightFrame)
    notebook.add(tk.Frame(notebook, bg="white", width=709, height=725, name="1"), text="GRAPH")
    notebook.place(x=5, y=5)
     
    '''  ===                                          ONGLET 1                                            === '''
     
     
    Liste_TEST = [11.81, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6, 11.81, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6,11.81, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6, 11.81, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6]
    y2 = [1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74, 1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74,1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74, 1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74]
     
    chiffre_inf = IntVar()
    chiffre_inf.set(floor(min(Liste_TEST)))                                                   # arrondi au plus bas
    chiffre_sup = IntVar()
    chiffre_sup.set(ceil(max(Liste_TEST)))                                                  # arrondi au plus haut
    print("chiffre_inf", chiffre_inf.get(), "chiffre_sup", chiffre_sup.get())
     
     
    # Crée un graphique de 1x1 (Y X) pouces avec une résolution de 96 points par pouce
    fig = plt.Figure(figsize=(1, 1), dpi=96)
     
    # Adjust the bottom size according to the
    # requirement of the user
    fig.subplots_adjust(bottom=0.25)
     
    # Crée une vue dans une grille de 1 ligne x 1 colonne -- Y  X  GaucheDroite
    ax1 = fig.add_subplot(1,1, 1, frameon=True, xlim=(0, len(Liste_TEST)), ylim=(chiffre_inf.get(), chiffre_sup.get()))
     
    # Intégration du second axe Y [Right] - make twin axis based on axis X
    ax2 = ax1.twinx()
     
    # Affiche/Inhibe & Couleur -- Axes XY Haut-Bas - Droite-Gauche
    # ['bottom'] ['top']
    ax1.spines['bottom'].set_color('none')
    ax1.spines['top'].set_color('none')
    # ['right'] ['left']
    ax2.spines['right'].set_color('#e45cda')   															# couleur rose
    ax1.spines['left'].set_color('#FF0000')																	# couleur rouge
     
    # Position Axe Y ['left']
    ax1.yaxis.set_ticks_position('left')
    ax1.spines['left'].set_position(('data', 0))
     
    # Couleurs des Echelles de l'axe des abscisses et des deux xes des ordonnées
    ax1.tick_params(labelcolor='#FF0000', left=True)
    ax2.tick_params(labelcolor='#e45cda', right=True)
     
     
    ax1.plot(range(len(Liste_TEST)), Liste_TEST, color="red", linewidth=.85, linestyle="dotted", label='Effective')
    ax2.plot(range(len(Liste_TEST)), y2, color='#e45cda', linewidth=.85, linestyle="solid")
     
    # Choose the Slider color
    slider_color = 'White'
     
    # Set the axis and slider position in the plot
    # Origine XY = Coin BasGauche --> [Position Origine X, Position Origine Y, Longueur Barre. Largeur Barre]
    axis_position = fig.add_axes([0.1, 0.96, 0.65, 0.03], facecolor=slider_color)
    # Valeur de Départ - Fin de la Scrollbar
    slider_position = Slider(axis_position, 'Pos', 0.1, 90.0)
     
    # update() function to change the graph when the
    # slider is in use
    def update(val):
    	pos = slider_position.val
    	fig.axis([pos, pos+10, -1, 1])
    	fig.canvas.draw_idle()
     
     
    # update function called using on_changed() function
    slider_position.on_changed(update)
     
    graph = FigureCanvasTkAgg(fig, master=notebook.winfo_children()[0])
    canvas = graph.get_tk_widget()
    canvas.config(width=700, height=570, relief=RIDGE, borderwidth=2)
    canvas.place(x=2, y=50)
     
     
    root.mainloop()

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 398
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 398
    Points : 36 957
    Points
    36 957
    Par défaut
    Salut,

    La démarche est de commencer par étudier la demo sur le Slider donnée dans la documentation puis on essaie de l'adapter a ses besoins.

    - W

  3. #3
    Membre à l'essai
    Homme Profil pro
    manutentionnaire
    Inscrit en
    Décembre 2020
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : manutentionnaire

    Informations forums :
    Inscription : Décembre 2020
    Messages : 31
    Points : 13
    Points
    13
    Par défaut
    je cherche à faire ceci

    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
    # Import libraries using import keyword
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.widgets import Slider
     
    # Setting Plot and Axis variables as subplots()
    # function returns tuple(fig, ax)
    Plot, Axis = plt.subplots()
     
    # Adjust the bottom size according to the
    # requirement of the user
    plt.subplots_adjust(bottom=0.25)
     
    # Set the x and y axis to some dummy data
    t = np.arange(0.0, 100.0, 0.1)
    s = np.sin(2*np.pi*t)
     
    # plot the x and y using plot function
    l = plt.plot(t, s)
     
    # Choose the Slider color
    slider_color = 'green'
     
    # Set the axis and slider position in the plot
     
    # Origine XY = Coin BasGauche --> [Position Origine X, Position Origine Y, Longueur Barre. Largeur Barre]
    axis_position = plt.axes([0.2, 0.1, 0.65, 0.03], facecolor = slider_color)
    # Valeur de Départ - Fin de la Scrollbar
    slider_position = Slider(axis_position, 'Pos', 0.1, 90.0)
     
    # update() function to change the graph when the
    # slider is in use
    def update(val):
    	pos = slider_position.val
    	Axis.axis([pos, pos+10, -1, 1])
    	Plot.canvas.draw_idle()
     
    # update function called using on_changed() function
    slider_position.on_changed(update)
     
    # Display the plot
    plt.show()

  4. #4
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 398
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 398
    Points : 36 957
    Points
    36 957
    Par défaut
    Citation Envoyé par LS_Soleil Voir le message
    je cherche à faire ceci
    Qui devrait fonctionner...

    - W

  5. #5
    Membre à l'essai
    Homme Profil pro
    manutentionnaire
    Inscrit en
    Décembre 2020
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : manutentionnaire

    Informations forums :
    Inscription : Décembre 2020
    Messages : 31
    Points : 13
    Points
    13
    Par défaut
    voici la solution que j'ai trouvé

    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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    # coding:utf-8
    #version 3.x python
     
    # ==================================================
    #                                         ID python 3.7.2
    # ==================================================
    from tkinter import *
    import tkinter as tk
    from tkinter import ttk
    print("TkVersion", TkVersion)
    print("TclVersion", TclVersion)
    print("Python version", sys.version_info)
    import sys; print('Python %s on %s' % (sys.version, sys.platform))
     
    # ==================================================
    #                                         matplotlib 3.3.3
    # ==================================================
    from pylab import *                                                                                            # importe tout de matplotlib
    import matplotlib.pyplot as plt
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredAuxTransformBox
    from matplotlib.widgets import Slider
     
    print("MatPlotLib version : ", matplotlib.__version__)
    print('MatPlotLib version : {}'.format(matplotlib.__version__))
     
    # ==================================================
    #                                  Notebook - Hauteur Largeur
    # ==================================================
    def _on_tab_changed(event):
    	print("\n")
    	'''
            update_idletasks
            Python est tkinter peuvent "mettre en sommeil" (idle) certaines tâches d'affichage, non essentielles, par exemple
            le redimensionnement des contrôles. Ces mises à jour de l'affichage sont dîtes dormantes. Pour forcer la mise à jour
            d'un tel affichage, utilisez .update_idletasks ( ) sans attendre la fin du traitement des gestionnaires d’événement et son retour au début de la boucle principale.
            '''
     
    	nb = event.widget
    	nb.update_idletasks()
     
    	tab = nb.nametowidget(nb.select())
     
    	nb.configure(height=tab.winfo_reqheight())														# Dimensionnement Hauteur
    	nb.configure(width=tab.winfo_reqwidth())													    # Dimensionnement Largeur
     
     
    def Create_notebook(master=None, **kw):
    	nb = ttk.Notebook(master, **kw)
    	nb.bind("<<NotebookTabChanged>>", _on_tab_changed)
    	return nb
     
    # ==================================================
    #                                  Fenêtre Principal - Configuration
    # ==================================================
    root = tk.Tk()                                                                                                    # Crée une instance Tk class
    root.title("Titre")
    root.resizable(False, False)                                                                                 # Fenêtre verrouillée
     
    window_height = 800
    window_width = 900
     
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
     
    x_cordinate = int((screen_width/2) - (window_width/2))
    y_cordinate = int((screen_height/2) - (window_height/2))
     
    root.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
     
    # ==================================================
    #                                  Frames
    # ==================================================
     
    # --- Frame gauche ---
    RightFrame = tk.LabelFrame(root, text="[Label]", font=('verdana', 8, ''), foreground="blue", relief=SOLID, borderwidth=0)
    RightFrame.place(x=130, y=5, width=900, height=900)
    RightFrame.anchor(anchor="center")
     
    # Notebook
    notebook = Create_notebook(RightFrame)
    notebook.add(tk.Frame(notebook, bg="white", width=709, height=725, name="1"), text="GRAPH")
    notebook.place(x=5, y=5)
     
    '''  ===                                          ONGLET 1                                            === '''
     
     
    Liste_TEST = [5.16, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6, 5.16, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6, 5.16, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6, 5.16, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6, 5.16, 4.91, 4.62, 4.19, 4.35, 4.22, 4.03, 4.31, 4.06, 4.23, 4.01, 4.28, 4.06, 3.81, 4.05, 4.04, 4.13, 4.08, 3.99, 4.05, 4.15, 4.26, 4.3, 4.35, 4.77, 4.65, 4.77, 4.52, 4.6]
    y2 = [1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74, 1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74,1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74, 1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74, 1.46,1.51,1.52,1.5,1.56,1.57,1.66,1.65,1.61,1.61,1.61,1.63,1.65,1.65,1.64,1.66,1.63,1.63,1.63,1.61,1.7,1.73,1.73,1.73,1.69,1.72,1.72,1.71,1.74]
    print("Liste_TEST >", len(Liste_TEST), "<>", Liste_TEST)
    print("y2 >", len(y2), "<>", y2)
     
    chiffre_inf = IntVar()
    chiffre_inf.set(floor(min(Liste_TEST)))                                                   # arrondi au plus bas
    chiffre_sup = IntVar()
    chiffre_sup.set(ceil(max(Liste_TEST)))                                                  # arrondi au plus haut
    print("chiffre_inf", chiffre_inf.get(), "chiffre_sup", chiffre_sup.get())
     
    # Création du graphique
    # 1x1 (Y X) pouces - Résolution 96 points par pouce
    fig = plt.Figure(figsize=(1, 1), dpi=96)
     
    canvas = FigureCanvasTkAgg(fig, master=notebook.winfo_children()[0])
    canvas.get_tk_widget().config(width=700, height=370, relief=RIDGE, borderwidth=2)
    canvas.get_tk_widget().place(x=2, y=50)
     
    # Crée une vue dans une grille de 1 ligne x 1 colonne -- Y  X  GaucheDroite
    ax1 = fig.add_subplot(1,1, 1, frameon=True, xlim=(0, len(Liste_TEST)), ylim=(chiffre_inf.get(), chiffre_sup.get()))
    fig.subplots_adjust(bottom=0.25)
     
    # Intégration du second axe Y [Right] - make twin axis based on axis X
    ax2 = ax1.twinx()
     
    # Affiche/Inhibe & Couleur -- Axes XY Haut-Bas - Droite-Gauche
    # ['bottom'] ['top']
    ax1.spines['bottom'].set_color('none')
    ax1.spines['top'].set_color('none')
    # ['right'] ['left']
    ax2.spines['right'].set_color('#e45cda')   															    # couleur rose
    ax1.spines['left'].set_color('#FF0000')																	# couleur rouge
     
    # Position Axe Y ['left']
    ax1.yaxis.set_ticks_position('left')
    # ax1.spines['left'].set_position(('data', 0))                                                          # Axe Y1 se déplace   ????????????
     
    # Couleurs des Echelles de l'axe des abscisses et des deux xes des ordonnées
    ax1.tick_params(labelcolor='#FF0000', left=True)
    ax2.tick_params(labelcolor='#e45cda', right=True)
     
    # Configuration de la grille
     
    # Graduation de l'axe (0,X) des abscisses et de l'axe (0,Y) des ordonnées
    major_ticks = np.arange(chiffre_inf.get(), chiffre_sup.get(), 1)                          # Chiffre Bas, Chifffre Haut, PAS
    minor_ticks = np.arange(chiffre_inf.get(), chiffre_sup.get(), 0.5)                        # Chiffre Bas, Chifffre Haut, PAS intermédiare
    ax1.set_yticks(major_ticks * 1)																		# donne la position des graduations sur l'axe des y
    ax1.set_yticks(minor_ticks * 1, minor=True)														# donne la position des graduations sur l'axe des y
    ax1.grid(which='minor', alpha=0.2)
    ax1.grid(which='major', alpha=0.5)
    ax1.grid(True)
     
    #
    ax1.set_xlabel("Nombre de plein(s)", fontsize=6)
    ax1.set_ylabel("Litre(s)", fontsize=6)
    ax1.set_title("<" + "Titre tableau" + ">", fontsize=8, color='dimgrey')
     
     
    # Configuration des Axes
    ax1.axis([0, len(Liste_TEST), chiffre_inf.get(), chiffre_sup.get()])                             # Limite des Axes ([Xmin, Xmax, Ymin, Ymax])
     
    # Configuration Slider
    ax_slide = fig.add_axes([0.2, 0.1, 0.65, 0.03])														# Origine XY = Coin BasGauche --> [Position Origine X, Position Origine Y, Longueur Barre. Largeur Barre]
     
     
    # Propriétés du Slider
    # (ax, label, valmin, valmax, valinit=None, valfmt=None, closedmin=True, closedmax=True, dragging=True, valstep=None, orientation='horizontal', track_color='lightgrey', handle_style=None, **kwargs)
    # valiinit : Les positions initiales du curseur. Si aucun, les positions initiales seront aux 25% et 75% de la plage.
    # Plage des valeur X --> valmin, valmax
    #                      (ax        , label           , valmin, valmax           , valinit    , valstep)
    s_factor = Slider(ax_slide, '', 0, len(Liste_TEST) - 50, valinit=0, valstep=1)
     
     
     
    # Impression des courbes
    # linestyle -->  '-', '--', '-.', ':', 'None', ' ', '', 'solid', 'dashed', 'dashdot', 'dotted'
    # print("Liste_TEST >", Liste_TEST)
    ax1.plot(range(len(Liste_TEST)), Liste_TEST, color="red", linewidth=.85, linestyle="solid", label='Effective')
    ax2.plot(range(len(Liste_TEST)), y2, color='#e45cda', linewidth=.85, linestyle="solid")
     
    def update1(val):
    	pos = s_factor.val
    	print("pos", pos)
    	# la valeur 50 est idem sur s_factor
    	ax1.axis([pos, pos+50, chiffre_inf.get(), chiffre_sup.get()])									# axis([Xmin, Xmax, Ymin, Ymax])
    	fig.canvas.draw_idle()
     
    s_factor.on_changed(update1)
     
     
    root.mainloop()

  6. #6
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 398
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 398
    Points : 36 957
    Points
    36 957
    Par défaut
    Citation Envoyé par LS_Soleil Voir le message
    voici la solution que j'ai trouvé...
    Bravo... donc vous n'avez pas de problème et pouvez clore cette discussion.

    - W

  7. #7
    Membre à l'essai
    Homme Profil pro
    manutentionnaire
    Inscrit en
    Décembre 2020
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : manutentionnaire

    Informations forums :
    Inscription : Décembre 2020
    Messages : 31
    Points : 13
    Points
    13
    Par défaut
    La seule chose, que je regrette, c'est que le graphique initiale, n'est plus affiché, une fois l'utilisation du Slider.
    Donc, j'aimerai le retour du graphique initial, lors de la mise du Slider en position 0.

    une idée, s'il vous plaît?

    merci

  8. #8
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 398
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 398
    Points : 36 957
    Points
    36 957
    Par défaut
    Citation Envoyé par LS_Soleil Voir le message
    Donc, j'aimerai le retour du graphique initial, lors de la mise du Slider en position 0.

    une idée, s'il vous plaît?
    C'est vous qui avez écrit ce code?

    ligne 174: ax1.axis([pos, pos+50, ...) si pos est nul alors, il faudrait avoir len(Liste_TEST) a la place de pos+50.

    - W

  9. #9
    Membre à l'essai
    Homme Profil pro
    manutentionnaire
    Inscrit en
    Décembre 2020
    Messages
    31
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : manutentionnaire

    Informations forums :
    Inscription : Décembre 2020
    Messages : 31
    Points : 13
    Points
    13
    Par défaut
    Merci pour l'aide.

    Le but est de répondre à la question suivante :
    Combien coûte le véhicule, en tenant compte, des frais du carburant, des taxes (assurances, plaque minéralogique, parking, etc..), de la maintenance.
    Un historique est établit selon l'année sélectionnée, ou depuis l'acquisition du véhicule.
    Pour le carburant, le graphique donne un suivis de la consommation au 100 km et du prix du carburant.

    je me suis attelé sur ce petit projet.
    N'étant pas un programmeur chevronné, je consulte les documentations, les exemples, pour avancer.

    Bonne journée

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. problème Matplotlib slider
    Par accoumar dans le forum Général Python
    Réponses: 7
    Dernier message: 25/02/2020, 09h44
  2. [Python 3.X] matplotlib slider widget
    Par marco056 dans le forum Général Python
    Réponses: 10
    Dernier message: 24/05/2019, 19h15
  3. [MFC]Utilisation d'un SLIDER , problème de conversion
    Par sylvain_c42 dans le forum MFC
    Réponses: 1
    Dernier message: 10/05/2005, 14h31
  4. [MFC] Plusieurs sliders en un
    Par bigquick dans le forum MFC
    Réponses: 3
    Dernier message: 23/02/2005, 17h53
  5. affichage valeur d'un Slider
    Par djiwalloo dans le forum MFC
    Réponses: 4
    Dernier message: 24/11/2004, 10h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo