[Python] Python 3G Graph- how to make plot interactive?

Discussão em 'Python' iniciado por Stack, Dezembro 17, 2024.

  1. Stack

    Stack Membro Participativo

    OSX 12.7 Python 3

    I have a python script that I I have set the defaut Open with: Python Launcher 3.app File is a Plot3D-V2.py, it runs quickly but in order to update it I have to constantly re-reun the script.

    I have looked at a number of questions involving making the graph interactive (remains open while changes to spreadsheet data is made0, closing the plot window terminates the script, and any changes to the spreadsheet cannot be seen without re-running the script.

    here is my code:

    import pandas as pd

    import matplotlib.pyplot as plt
    from matplotlib.pyplot import plot, ion, draw, show
    import mpl_toolkits.mplot3d

    import seaborn as sns
    sns.set_style("whitegrid", {'axes.grid' : False})

    import tkinter as tk
    from tkinter import filedialog
    from tkinter import Toplevel
    root = tk.Tk()
    root.withdraw()
    file_path = filedialog.askopenfilename()
    print(file_path)


    df = pd.read_excel(file_path)
    print(df.head)
    print(df.columns)


    root.iconify()

    fig = plt.figure(figsize=(9,9))
    ax = plt.axes(projection='3d')

    ax.set_xlim(0.2, 0.4)

    ax.set_ylim(0.6, 0.2)

    ax.set_zlim(0.2, 0.4)

    for i in range(len(df)):
    ax.scatter3D(df['R'], df['G'], df['B'],
    marker=df['M'], c=df['C'], alpha=1.0)

    ax.set_xlabel('Red')
    ax.set_ylabel('Green')
    ax.set_zlabel('Blue')

    draw()

    plt.show(block=False)

    plt.pause(1)

    plt.show(block=True)

    plt.show()


    is there a simple way to embed a 'rereun script' button into the plot windo?

    Continue reading...

Compartilhe esta Página