【发布时间】:2022-01-17 05:14:40
【问题描述】:
我想将此散点图添加到我的 tkinter gui。我在我的 jupyter notebook 上运行了它,它可以工作,但我不确定如何将它实现到 tkinter gui。
这是图表应该是的窗口 enter image description here
这是我的 jupyter 笔记本上的代码:
### Import libraries
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
### Import dataset
players_df = pd.read_csv("player_locations.txt")
players_df
### Draw Seaborn Scatter Plot to find location between lat and long
sns.scatterplot(x = players_df["longitude"], y = players_df["latitude"], hue = players_df["Player"])
这是我的 gui 上用于分析窗口的代码:
from tkinter import *
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import csv
import pandas as pd
import seaborn as sns
from matplotlib import animation
from matplotlib.animation import FuncAnimation
from matplotlib import style
players_df = pd.read_csv("player_locations.txt")
players_df
class addAnalysis(Toplevel):
def __init__(self):
Toplevel.__init__(self)
self.geometry("650x650+620+200")
self.title("Analysis")
self.resizable(False,False)
#Frames
self.top=Frame(self,height=150,bg='white')
self.top.pack(fill=X)
self.bottomFrame=Frame(self,height=500,bg='#f1dead')
self.bottomFrame.pack(fill=X)
#heading
self.heading = Label(self.top, text='Player Analysis', font='arial 25 bold',
fg='#000000', bg='white')
self.heading.place(x=230, y=60)
#buttons
graph_button = Button(self.bottomFrame,text=' Graph ',
font='arial 14 bold',command = self.plot)
graph_button.place(x=10,y=380)
exit_button = Button(self.bottomFrame,text=' Exit ',
font='arial 14 bold',command = self.destroy)
exit_button.place(x=10,y=440)
# this is the part where I implement the scatter plot
def plot():
# Draw Seaborn Scatter Plot to find location between lat and long
scatter = self.sns.scatterplot(x = players_df["longitude"], y = players_df["latitude"], hue = players_df["Player"])
【问题讨论】:
标签: python user-interface tkinter plot seaborn