So I'm trying to write a small GUI that will allow an end use to plot X vs Y of any 2 columns in an Excel file. Here's my code:
import pandas as pd
import matplotlib.pyplot as plt
import tkinter as tk
my_base=pd.read_excel('my_base.xlsx', 'the_tab', index_col=None, na_values = ['NA'])
my_base_header = list(my_base.columns.values)
my_base['Generated Date'] = pd.to_datetime(my_base['Generated Date'])
main_win = tk.Tk()
def plot_graph():
print(option1.get())
print(option2.get())
my_base.plot(x = option1.get(), y = option2.get(), style = 'x')
plt.show()
option1 = tk.StringVar(main_win)
option1.set(my_base_header[0])
option2 = tk.StringVar(main_win)
option2.set(my_base_header[0])
opt1 = tk.OptionMenu(main_win, option1, *my_base_header)
opt1.pack()
opt2 = tk.OptionMenu(main_win, option2, *my_base_header)
opt2.pack()
runbtn = tk.Button(main_win, text = 'Plot', command = plot_graph)
runbtn.pack()
main_win.mainloop()
I can get the program to plot if I put the dataframe headers in directly like so:
my_base.plot(x = 'Generated Date', y = 'How many', style = 'x')
But when I use for example x = option1.get() in there I get this traceback
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
my_base.plot(x= x_ax, y = y_ax, style = 'x')
File "C:\Python34\lib\site-packages\pandas\tools\plotting.py", line 2485, in plot_frame
**kwds)
File "C:\Python34\lib\site-packages\pandas\tools\plotting.py", line 2325, in _plot
plot_obj.generate()
File "C:\Python34\lib\site-packages\pandas\tools\plotting.py", line 921, in generate
self._compute_plot_data()
File "C:\Python34\lib\site-packages\pandas\tools\plotting.py", line 997, in _compute_plot_data
'plot'.format(numeric_data.__class__.__name__))
TypeError: Empty 'Series': no numeric data to plot