#๐ Embedding a matplotlib graph using tkinter GUI
9 messages ยท Page 1 of 1 (latest)
@light girder
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
My current method in the main window:
def show_monthly_average(self): PlotWindow(self, rainfall.Rainfall().plot_average_monthly_rainfall())
Method in the rainfall module
`def plot_average_monthly_rainfall(self):
avg_monthly_rf = np.mean(self.monthly_rf,0)
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
plt.bar(months, avg_monthly_rf, color='cyan', edgecolor = 'black')
plt.title('Average Monthly Rainfall')
plt.xlabel('Month')
plt.ylabel('Average Rainfall')
return len(avg_monthly_rf)`
plot window
class PlotWindow(tk.Toplevel): def __init__(self, master, plot_data): self.canvas = FigureCanvasTkAgg(plot_data, master=self) self.canvas.get_tk_widget().grid() self.canvas.draw()
right now if I use this in my code the graph prints but only once
and i get the AttributeError: 'int' object has no attribute 'set_canvas' traceback
@light girder
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.