I am using Python 3.5.3 on Debian 9.
Tkinter window crashes when clicking the button "Create Plot" to save a plot created using plotnine. The plot however gets successfully saved in the working directory. The code block stated below is a simple recreation of the aforementioned error I am encountering in a larger tkinter application. I am a newbie to python programming and generally use it for bioinformatics data analysis. Please help me.
import tkinter as tk
from fpdf import FPDF
import pandas as pd
from plotnine import *
def createPlot():
df = {"dates":[1,2,3,4,5,6], "amount":[21,22,18,19,25,15]}
df = pd.DataFrame(df)
plot = ggplot(aes(x="dates", y="amount"), data=df) + xlab("Dates") + ylab("Amount") #Create the base plot and axes
plot = plot + scale_x_continuous(breaks = list(df.dates)) #Format the axes
plot = plot + geom_line(aes(x=list(df.dates), y=list(df.amount)), data=df) #Create the actual data plot
plot.save(filename = 'plot.png', dpi=300, width=12, height=7, units="in") #Save the plot as a PNG image
# The GUI Mainloop
root=tk.Tk()
root.title("Test")
root.minsize(width=200,height=200)
root.maxsize(width=200,height=200)
CreatePlotButton=tk.Button(root,text="Create Plot",command= createPlot) #Button to create plots
CreatePlotButton.pack()
CreatePlotButton.place(x=20,y=100)
root.mainloop()
This is the warning that is generated from the terminal
/usr/local/lib/python3.5/dist-packages/plotnine/ggplot.py:706: UserWarning: Saving 12 x 7 in image.
from_inches(height, units), units))
/usr/local/lib/python3.5/dist-packages/plotnine/ggplot.py:707: UserWarning: Filename: plot.png
warn('Filename: {}'.format(filename))
I have also tried to run the application by commenting out the plot.save() line as shown in the code block below. The application does not crash on clicking the "Create Plot". It seems that the error is creeping in while I am trying to save the plot and not during generation of the plot using plotnine.
import tkinter as tk
from fpdf import FPDF
import pandas as pd
from plotnine import *
def createPlot():
df = {"dates":[1,2,3,4,5,6], "amount":[21,22,18,19,25,15]}
df = pd.DataFrame(df)
plot = ggplot(aes(x="dates", y="amount"), data=df) + xlab("Dates") + ylab("Amount") #Create the base plot and axes
plot = plot + scale_x_continuous(breaks = list(df.dates)) #Format the axes
plot = plot + geom_line(aes(x=list(df.dates), y=list(df.amount)), data=df) #Create the actual data plot
#plot.save(filename = 'plot.png', dpi=300, width=12, height=7, units="in") #Save the plot as a PNG image
# The GUI Mainloop
root=tk.Tk()
root.title("Test")
root.minsize(width=200,height=200)
root.maxsize(width=200,height=200)
CreatePlotButton=tk.Button(root,text="Create Plot",command= createPlot) #Button to create plots
CreatePlotButton.pack()
CreatePlotButton.place(x=20,y=100)
root.mainloop()
My larger application is almost ready except for this nagging error I am encountering. I would like my plot to be saved and the Tkinter window to remain open. I would be very thankful for any suggestions.