Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 上传csv文件后如何更新嵌入式matplotlib图形?_Python 3.x_Matplotlib_Tkinter - Fatal编程技术网

Python 3.x 上传csv文件后如何更新嵌入式matplotlib图形?

Python 3.x 上传csv文件后如何更新嵌入式matplotlib图形?,python-3.x,matplotlib,tkinter,Python 3.x,Matplotlib,Tkinter,当我第一次加载应用程序时,我有一个Tkinter UI(下图) 现在我想做的是点击“导入降雨CSV文件”,以便上传CSV文件。我使用以下代码执行此操作: browseButton_CSV = tk.Button(text="Import Rainfall CSV File", command=get_csv_rainfall, bg='green',fg='white',font=('helvetica', 12, 'bold')) 我的命令的功能如下: def get_c

当我第一次加载应用程序时,我有一个Tkinter UI(下图)

现在我想做的是点击“导入降雨CSV文件”,以便上传CSV文件。我使用以下代码执行此操作:

browseButton_CSV = tk.Button(text="Import Rainfall CSV File", command=get_csv_rainfall, bg='green',fg='white',font=('helvetica', 12, 'bold'))
我的命令的功能如下:

def get_csv_rainfall():  # function for the button to execute
global rainfall_data

import_file_path = filedialog.askopenfilename()
print(import_file_path)
pullData = open(import_file_path, "r").read()  # first graph
dataArray = pullData.split('\n')
for eachLine in dataArray:
    if len(eachLine)>1:
        x, y = eachLine.split(',')
        x_rainfall.append(int(x))
        y_rainfall.append(int(y))
print("Inside: " + str(x_rainfall))
问题是,在我点击按钮并上传csv后,该函数负责添加x和y坐标,我的嵌入图形不会更新。

以下是我的图形代码供参考:

fig = plt.figure(figsize=(4, 4))

plt.plot(x_dengue, y_dengue, color='green', label='dengue cases')      # plot the first graph in the same graph
plt.plot(x_rainfall, y_rainfall, color='blue', label='rainfall')    # plot the second graph in the same graph
plt.xlabel('weeks')
plt.ylabel('number of dengue cases/rainfall')
plt.title('Cases of dengue and rainfall')

print("Rainfall" + str(x_rainfall))
print("Dengue" + str(x_dengue))
下面的两个print语句在应用程序首次启动时仅打印一次,并且是空列表。当我点击上传csv按钮时,它不会再次打印