Embedding Python Pandas plot to Tkinter GUI canvas widget 'update_idletasks' issue
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to embed the panda plot to Tkinter.
I am able to display it; however I receive AttributeError: 'NoneType' object has no attribute 'update_idletasks' error, when the program first run and close.
Here is my code:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import pandas as pd
import tkinter as tk
import os
matplotlib.use("TkAgg")
LOCO_ANCHOR_DATA = "data_loco/loco_anchor"
POS_DATA = "data_loco/pos_data"
class ReportWindow:
def __init__(self, master):
self.master = master
tk.Label(self.master, text="Report").grid(row=0, column=0)
self.lf = tk.LabelFrame(self.master, text="Plot").grid(row=1, column=0, padx=3, pady=3)
self.draw_plot()
def draw_plot(self):
fig = self.plot_data()
canvas = FigureCanvasTkAgg(fig, master=self.lf)
canvas.get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
def read_anchor_file(self, data_path=LOCO_ANCHOR_DATA):
anchor_csv_path = os.path.join(data_path, "anchor_pos.csv")
# print(pd.read_csv(csv_path))
return pd.read_csv(anchor_csv_path)
def read_pos_file(self, data_path=POS_DATA):
pos_csv_path = os.path.join(data_path, "real_time_data.csv")
# print(pd.read_csv(pos_csv_path))
return pd.read_csv(pos_csv_path)
def plot_data(self):
fig = Figure(figsize=(5,4), dpi=100)
plt.rc('grid', linestyle="--", color='black')
axis = fig.add_subplot(111)
anchor_pos_data = self.read_anchor_file()
drone_pos_data = self.read_pos_file()
drone_pos_data.plot(kind="scatter", x="xpos", y="ypos", alpha=0.4,
s=50, label="Real Time Position",
c="zpos", cmap=plt.get_cmap("jet"), colorbar=True, ax=axis)
anchor_pos_data.plot(kind="scatter", x="y_direction", y="x_direction",
label="Anchor Positions",
color=(0, 0, 0), colorbar=False, ax=axis)
plt.colormaps()
plt.title("Flight Path Map")
plt.grid(True)
plt.legend(loc=0)
# plt.show()
return fig
if __name__ == '__main__':
root = tk.Tk()
report_gui = ReportWindow(master=root)
root.mainloop()
Even though I am passing a Figure object, why do I still receive that error?
Best Regards
SOLUTION:
In python when you do a().b(), the result of the expression is whatever b() returns, therefore LabelFrame(...).grid(...) will return None.
So solution is changing the LabelFrame initializing to the followings:
self.lf = tk.LabelFrame(self.master, text="Plot")
self.lf.grid(row=1, column=0, padx=3, pady=3)
Then I stoped seeing the "update_idletasks" issue
python pandas tkinter
add a comment |
I am trying to embed the panda plot to Tkinter.
I am able to display it; however I receive AttributeError: 'NoneType' object has no attribute 'update_idletasks' error, when the program first run and close.
Here is my code:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import pandas as pd
import tkinter as tk
import os
matplotlib.use("TkAgg")
LOCO_ANCHOR_DATA = "data_loco/loco_anchor"
POS_DATA = "data_loco/pos_data"
class ReportWindow:
def __init__(self, master):
self.master = master
tk.Label(self.master, text="Report").grid(row=0, column=0)
self.lf = tk.LabelFrame(self.master, text="Plot").grid(row=1, column=0, padx=3, pady=3)
self.draw_plot()
def draw_plot(self):
fig = self.plot_data()
canvas = FigureCanvasTkAgg(fig, master=self.lf)
canvas.get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
def read_anchor_file(self, data_path=LOCO_ANCHOR_DATA):
anchor_csv_path = os.path.join(data_path, "anchor_pos.csv")
# print(pd.read_csv(csv_path))
return pd.read_csv(anchor_csv_path)
def read_pos_file(self, data_path=POS_DATA):
pos_csv_path = os.path.join(data_path, "real_time_data.csv")
# print(pd.read_csv(pos_csv_path))
return pd.read_csv(pos_csv_path)
def plot_data(self):
fig = Figure(figsize=(5,4), dpi=100)
plt.rc('grid', linestyle="--", color='black')
axis = fig.add_subplot(111)
anchor_pos_data = self.read_anchor_file()
drone_pos_data = self.read_pos_file()
drone_pos_data.plot(kind="scatter", x="xpos", y="ypos", alpha=0.4,
s=50, label="Real Time Position",
c="zpos", cmap=plt.get_cmap("jet"), colorbar=True, ax=axis)
anchor_pos_data.plot(kind="scatter", x="y_direction", y="x_direction",
label="Anchor Positions",
color=(0, 0, 0), colorbar=False, ax=axis)
plt.colormaps()
plt.title("Flight Path Map")
plt.grid(True)
plt.legend(loc=0)
# plt.show()
return fig
if __name__ == '__main__':
root = tk.Tk()
report_gui = ReportWindow(master=root)
root.mainloop()
Even though I am passing a Figure object, why do I still receive that error?
Best Regards
SOLUTION:
In python when you do a().b(), the result of the expression is whatever b() returns, therefore LabelFrame(...).grid(...) will return None.
So solution is changing the LabelFrame initializing to the followings:
self.lf = tk.LabelFrame(self.master, text="Plot")
self.lf.grid(row=1, column=0, padx=3, pady=3)
Then I stoped seeing the "update_idletasks" issue
python pandas tkinter
add a comment |
I am trying to embed the panda plot to Tkinter.
I am able to display it; however I receive AttributeError: 'NoneType' object has no attribute 'update_idletasks' error, when the program first run and close.
Here is my code:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import pandas as pd
import tkinter as tk
import os
matplotlib.use("TkAgg")
LOCO_ANCHOR_DATA = "data_loco/loco_anchor"
POS_DATA = "data_loco/pos_data"
class ReportWindow:
def __init__(self, master):
self.master = master
tk.Label(self.master, text="Report").grid(row=0, column=0)
self.lf = tk.LabelFrame(self.master, text="Plot").grid(row=1, column=0, padx=3, pady=3)
self.draw_plot()
def draw_plot(self):
fig = self.plot_data()
canvas = FigureCanvasTkAgg(fig, master=self.lf)
canvas.get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
def read_anchor_file(self, data_path=LOCO_ANCHOR_DATA):
anchor_csv_path = os.path.join(data_path, "anchor_pos.csv")
# print(pd.read_csv(csv_path))
return pd.read_csv(anchor_csv_path)
def read_pos_file(self, data_path=POS_DATA):
pos_csv_path = os.path.join(data_path, "real_time_data.csv")
# print(pd.read_csv(pos_csv_path))
return pd.read_csv(pos_csv_path)
def plot_data(self):
fig = Figure(figsize=(5,4), dpi=100)
plt.rc('grid', linestyle="--", color='black')
axis = fig.add_subplot(111)
anchor_pos_data = self.read_anchor_file()
drone_pos_data = self.read_pos_file()
drone_pos_data.plot(kind="scatter", x="xpos", y="ypos", alpha=0.4,
s=50, label="Real Time Position",
c="zpos", cmap=plt.get_cmap("jet"), colorbar=True, ax=axis)
anchor_pos_data.plot(kind="scatter", x="y_direction", y="x_direction",
label="Anchor Positions",
color=(0, 0, 0), colorbar=False, ax=axis)
plt.colormaps()
plt.title("Flight Path Map")
plt.grid(True)
plt.legend(loc=0)
# plt.show()
return fig
if __name__ == '__main__':
root = tk.Tk()
report_gui = ReportWindow(master=root)
root.mainloop()
Even though I am passing a Figure object, why do I still receive that error?
Best Regards
SOLUTION:
In python when you do a().b(), the result of the expression is whatever b() returns, therefore LabelFrame(...).grid(...) will return None.
So solution is changing the LabelFrame initializing to the followings:
self.lf = tk.LabelFrame(self.master, text="Plot")
self.lf.grid(row=1, column=0, padx=3, pady=3)
Then I stoped seeing the "update_idletasks" issue
python pandas tkinter
I am trying to embed the panda plot to Tkinter.
I am able to display it; however I receive AttributeError: 'NoneType' object has no attribute 'update_idletasks' error, when the program first run and close.
Here is my code:
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import pandas as pd
import tkinter as tk
import os
matplotlib.use("TkAgg")
LOCO_ANCHOR_DATA = "data_loco/loco_anchor"
POS_DATA = "data_loco/pos_data"
class ReportWindow:
def __init__(self, master):
self.master = master
tk.Label(self.master, text="Report").grid(row=0, column=0)
self.lf = tk.LabelFrame(self.master, text="Plot").grid(row=1, column=0, padx=3, pady=3)
self.draw_plot()
def draw_plot(self):
fig = self.plot_data()
canvas = FigureCanvasTkAgg(fig, master=self.lf)
canvas.get_tk_widget().grid(row=1, column=0, padx=5, pady=5)
def read_anchor_file(self, data_path=LOCO_ANCHOR_DATA):
anchor_csv_path = os.path.join(data_path, "anchor_pos.csv")
# print(pd.read_csv(csv_path))
return pd.read_csv(anchor_csv_path)
def read_pos_file(self, data_path=POS_DATA):
pos_csv_path = os.path.join(data_path, "real_time_data.csv")
# print(pd.read_csv(pos_csv_path))
return pd.read_csv(pos_csv_path)
def plot_data(self):
fig = Figure(figsize=(5,4), dpi=100)
plt.rc('grid', linestyle="--", color='black')
axis = fig.add_subplot(111)
anchor_pos_data = self.read_anchor_file()
drone_pos_data = self.read_pos_file()
drone_pos_data.plot(kind="scatter", x="xpos", y="ypos", alpha=0.4,
s=50, label="Real Time Position",
c="zpos", cmap=plt.get_cmap("jet"), colorbar=True, ax=axis)
anchor_pos_data.plot(kind="scatter", x="y_direction", y="x_direction",
label="Anchor Positions",
color=(0, 0, 0), colorbar=False, ax=axis)
plt.colormaps()
plt.title("Flight Path Map")
plt.grid(True)
plt.legend(loc=0)
# plt.show()
return fig
if __name__ == '__main__':
root = tk.Tk()
report_gui = ReportWindow(master=root)
root.mainloop()
Even though I am passing a Figure object, why do I still receive that error?
Best Regards
SOLUTION:
In python when you do a().b(), the result of the expression is whatever b() returns, therefore LabelFrame(...).grid(...) will return None.
So solution is changing the LabelFrame initializing to the followings:
self.lf = tk.LabelFrame(self.master, text="Plot")
self.lf.grid(row=1, column=0, padx=3, pady=3)
Then I stoped seeing the "update_idletasks" issue
python pandas tkinter
python pandas tkinter
edited Feb 15 at 13:29
Vignesh Bayari R.
428212
428212
asked Nov 15 '18 at 11:35
AybarsAybars
304211
304211
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318586%2fembedding-python-pandas-plot-to-tkinter-gui-canvas-widget-update-idletasks-iss%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318586%2fembedding-python-pandas-plot-to-tkinter-gui-canvas-widget-update-idletasks-iss%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown