def test_graph2(self): """ http://data.geus.dk/JupiterWWW/borerapport.jsp?atlasblad=0&loebenr=0&bogstav=&dgunr=230.++205&submit=Vis+boringsdata https://www.linuxquestions.org/questions/programming-9/python-matplotlib-postgresql-xaxis-as-dates-4175445040/ """ from jupiter_db import JupiterDb import psycopg2 from matplotlib import pyplot as plot, dates db = JupiterDb() params = db.get_dbparams() conn = psycopg2.connect(**params) #psycopg2.connect('dbname=foo user=bar') cur = conn.cursor() cur.execute(""" SELECT amount, sampledate FROM jupiter.mstmvw_chemanalysis WHERE long_text ilike 'nitrat' AND boreholeno = '230. 205' """) data = cur.fetchall() cur.close() conn.close() ms, dt = zip(*data) dt = dates.date2num(dt) plot.plot_date(dt, ms) plot.xticks(rotation='vertical') plot.show() return True
def test_graph1(self): """ http://data.geus.dk/JupiterWWW/borerapport.jsp?atlasblad=0&loebenr=0&bogstav=&dgunr=230.++205&submit=Vis+boringsdata https://www.linuxquestions.org/questions/programming-9/python-matplotlib-postgresql-xaxis-as-dates-4175445040/ TODO: Why is test_graph1 faster than test_graph2 ? """ from jupiter_db import JupiterDb import psycopg2 from matplotlib import pyplot as plot, dates db = JupiterDb() params = db.get_dbparams() conn = psycopg2.connect( **params) #psycopg2.connect('dbname=foo user=bar') cur = conn.cursor() cur.execute(""" SELECT ca.amount, cs.sampledate FROM jupiter.borehole b --INNER JOIN jupiter.intake i USING (boreholeno) INNER JOIN jupiter.grwchemsample cs USING (boreholeno) INNER JOIN jupiter.grwchemanalysis ca ON ca.sampleid = cs.sampleid INNER JOIN jupiter.compoundlist cl ON ca.compoundno = cl.compoundno --INNER JOIN kort.lolland l ON st_dwithin(b.geom, l.geom, 0) WHERE cl.long_text ilike 'nitrat' AND b.boreholeno = '230. 205' ORDER BY cs.sampledate """) data = cur.fetchall() cur.close() conn.close() ms, dt = zip(*data) dt = dates.date2num(dt) plot.plot_date(dt, ms) plot.xticks(rotation='vertical') plot.show() return True