So I just installed Python3.3, Numpy, MySQL Connector, and Matplotlib. I have a table with a lot of data where I wrote a query that outputs it to something similar to this:
Timestamp(unix) Data(float)
1353000347 90.7000
1353007787 90.7000
1353015227 90.7000
1353000347 89.6899
1353007787 90.7000
1353015227 90.7000
So through a lot of trial and error and piecing together tutorials and other questions on here I ended up with this python script:
import matplotlib.pyplot as plt
import numpy as np
import mysql.connector
#Open DB Connection
cnx = mysql.connector.connect(host='localhost',database='db',
user='user',password='')
#Get Buffered Cursor
curA = cnx.cursor(buffered=True)
curA.execute(
"""
SELECT UNIX_TIMESTAMP(`timestamp`),`data1`
FROM `data`
"""
)
rows = np.array(curA.fetchall())
cnx.close()
x = rows[:,0]
y = rows[:,1]
plt.scatter(x,y,20,'r','o',None,None,None,None,0.05,0)
plt.show()
I have a lot of data points that will overlap (same coordinates) so I wanted the alpha real low. I got what I wanted here:
Anyways, what I wanted was to simply format the tick markers to dates (e.g. Month, Year). I searched a lot on this problem and found a similar question here, but I wasn't able to adapt it or make sense of how I could apply it to my script. Seems overly complicated for such a simple thing?