This code connects to MySQL and fetches a dataset which I read using pandas. Once the dataset is in a pandas dataframe, I need to plot it. But that throws an error. Here's the snipper
#!/usr/bin/python
import MySQLdb as mdb
import pandas as pd
import matplotlib.pyplot as plt
con = mdb.connect('hostname', 'username', 'password', 'database');
with con:
cur = con.cursor()
cur.execute("select month, post, comment, reply, dm, review")
rows = cur.fetchall()
df = pd.DataFrame( [[ij for ij in i] for i in rows] )
df.rename(columns={0: 'Month', 1: 'Post', 2: 'Comment', 3: 'Reply', 4: 'DM', 5: 'Review'}, inplace=True);
print(df.head(20))
df=df.set_index('Month')
df=df.astype(float)
df.plot(subplots=True)
plt.show()
Traceback (most recent call last):
File "random-exmaple.py", line 7, in <module>
plt.plot(x, y, "o")
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3307, in plot
ax = gca()
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 950, in gca
return gcf().gca(**kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 586, in gcf
return figure()
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 535, in figure
**kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 81, in new_figure_manager
return new_figure_manager_given_figure(num, figure)
File "/usr/local/lib/python2.7/site-
packages/matplotlib/backends/backend_tkagg.py", line 89, in new_figure_manager_given_figure
window = Tk.Tk()
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1745, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
How to fix this?
Sorry for the duplicate - Issue with tkinter, python and seaborn: _tkinter.TclError: no display name and no $DISPLAY environment variable