0

I try to do following: I have a frame, which I cleaned to plot some data. This new frame has 9 columns, one columns named "Cycle", four columns for temp [temp1,temp2,temp3,temp4] and four columns for pressure [p1,p2,p3,p4]. What I would like to achieve is following.

Create a small GUI (an .exe to be more precise), where user can select specific cycle number and based on selection he will get a figure including 4 plots. t1/p1, t2p2, t3,p3, t4/p4. I did manage to get the result I want, if I run the GUI through spyder, i.e. I can select for example cycle 1 and I get first plot. Then I select cycle 10 and I get next plot. However, If I create an .exe with pyinstaller, if I select for the first time a cycle I get first plot, but now if I select another cycle I dont get a new plot. It just doesn't happen anything.

I would be really happy if someone could help me

import PySimpleGUI as sg
import matplotlib.pyplot as plt
import pandas as pd
excel_path=sg.PopupGetFile("Select CSV file",title="Temperature / Pressure Plots")
df=pd.read_csv(str(excel_path),sep=";")
df.drop(df.columns[df.columns.str.contains("Unnamed")],1,inplace=True)
liste_cycle_number=list(df["CycleNr"].unique())
    
layout=[[
    sg.Text("Cycle Number",size=(20,1),justification="left"),sg.DropDown(values=liste_cycle_number,size=(10,1),key="Liste")],
    [sg.Button('Show'), sg.Button('Exit')]]
    
window = sg.Window('Window that stays open', 
while True:
    def plotting():
        def make_format(current, other):
            # current and other are axes
            def format_coord(x, y):
                # x, y are data coordinates
                # convert to display coords
                display_coord = current.transData.transform((x,y))
                inv = other.transData.inverted()
                # convert back to data coords with respect to ax
                ax_coord = inv.transform(display_coord)
                coords = [ax_coord, (x, y)]
                return ('Left: {:<40}    Right: {:<}'
                            .format(*['({:.3f}, {:.3f})'.format(x, y) for x,y in coords]))
            return format_coord    
            
            
        fig,ax=plt.subplots(2,2,sharex=True)
        fig.suptitle("Temperature / Pressure Curves for Cycle-Number"+" "+str(values["Liste"]), fontsize=16)
            
        pl1_1=ax[0,0].plot(filtered_df.index,filtered_df["eBar1"], 'r-',label="eBar1")
        ax2=ax[0,0].twinx()
        ax2.format_coord = make_format(ax2, ax[0,0])
        pl1_2=ax2.plot(filtered_df.index,filtered_df["eCelcius1"], 'g-',label="eCelcius1")
        plots1_1=pl1_1+pl1_2
        legends_1=[l.get_label() for l in plots1_1]
        ax[0,0].legend(plots1_1,legends_1,loc="best")
            
        pl2_1=ax[0,1].plot(filtered_df.index,filtered_df["eBar2"], 'r-',label="eBar2")
        ax2_2=ax[0,1].twinx()
        ax2_2.format_coord=make_format(ax2_2,ax[0,1])
        pl2_2=ax2_2.plot(filtered_df.index,filtered_df["eCelcius2"], 'g-',label="eCelcius2")
        plots2_2=pl2_1+pl2_2
        legends_2=[l.get_label() for l in plots2_2]     
        ax[0,1].legend(plots2_2,legends_2,loc="best")
            
        pl3_1=ax[1,0].plot(filtered_df.index,filtered_df["eBar3"], 'r-',label="eBar3")
        ax3_2=ax[1,0].twinx()
        ax3_2.format_coord=make_format(ax3_2,ax[1,0])
        pl3_2=ax3_2.plot(filtered_df.index,filtered_df["eCelcius3"], 'g-',label="eCelcius3")
        plots3_2=pl3_1+pl3_2
        legends_3=[l.get_label() for l in plots3_2]
        ax[1,0].legend(plots3_2,legends_3,loc="best")
            
        pl4_1=ax[1,1].plot(filtered_df.index,filtered_df["eBar4"], 'r-',label="eBar4")
        ax4_2=ax[1,1].twinx()
        ax4_2.format_coord=make_format(ax4_2,ax[1,1])
        pl4_2=ax4_2.plot(filtered_df.index,filtered_df["eCelcius4"], 'g-',label="eCelcius4")
        plots4_2=pl4_1+pl4_2
            
        legends_4=[l4.get_label() for l4 in plots4_2]
        ax[1,1].legend(plots4_2,legends_4,loc="best")
        plt.show()    
        
    event, values = window.read()
    filtered_df=df.loc[df["CycleNr"]==values["Liste"]]
    time=filtered_df.columns[13:].values.astype(float)
    usecols=filtered_df.columns[12:]
    filtered_df=filtered_df[usecols].T
    new_columns=["eBar1","eCelcius1","eBar2","eCelcius2",
              "eBar3","eCelcius3",
              "eBar4","eCelcius4"]
    filtered_df.columns=new_columns
    filtered_df=filtered_df.iloc[1:]
    filtered_df = filtered_df.apply(pd.to_numeric, errors='coerce')
    filtered_df.index=pd.to_numeric(filtered_df.index)
    # print(filtered_df)
    if event == None or event == 'Exit':
        break
    if event=="Show":
        plotting()
  
window.close()
Elijah
  • 1,814
  • 21
  • 27
SMS
  • 348
  • 2
  • 13
  • You should auto-format your code before posting it on SO. What happens if you run the file through Python and not spyder? – Elijah Jul 10 '20 at 02:16
  • Hey Eli, it happens the same as observed when I run the exe Code. So if I use CMD to run the code I observe the same behavior, i.e. only one plot and thats it. I don't know where my mistake is – SMS Jul 10 '20 at 07:16
  • 1
    Look at this https://stackoverflow.com/questions/5524858/matplotlib-show-doesnt-work-twice – Elijah Jul 10 '20 at 11:54
  • You sir or Mam saved my life. Thank you very very much – SMS Jul 11 '20 at 11:11
  • Does this answer your question? [matplotlib show() doesn't work twice](https://stackoverflow.com/questions/5524858/matplotlib-show-doesnt-work-twice) – Elijah Aug 17 '20 at 01:34

0 Answers0