plot custom variable in select time frame using python matplotlib

87 views
Skip to first unread message

mihec

unread,
Jan 19, 2023, 12:15:04 PM1/19/23
to weewx-user
Hi,
I would like to plot e.g. temperature and solar radiation from my sqlite3 weewx's database file for the whole last year or just selected season. Is there a code example how to do that? The problem I have is actually to extract the data from the database file. The plotting part I can handle.
Alternatively, is there a way to convert the selected timeframe from the database to the .csv file?
Thank you.

Tom Keffer

unread,
Jan 19, 2023, 2:25:16 PM1/19/23
to weewx...@googlegroups.com
WeeWX does not use matplotlib.

You would have to extract the data from the database, then use it. The command-line tool "sqlite3" can emit CSV files.

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/1b611686-0f84-4215-b1c3-d77e71f26664n%40googlegroups.com.

mihec

unread,
Jan 19, 2023, 2:49:04 PM1/19/23
to weewx-user
Thanks, I'll have a look how to do that.

četrtek, 19. januar 2023 ob 20:25:16 UTC+1 je oseba tke...@gmail.com napisala:

mihec

unread,
Jan 26, 2023, 7:31:44 AM1/26/23
to weewx-user
With some web search, I have a code example that can plot from the weewx.sdb directly. Maybe this will help someone.

import sqlite3, pandas , matplotlib.pyplot as plt
from datetime import datetime

conn = sqlite3.connect("weewx.sdb")
c = conn.cursor()

def ftoc(t):
    return float((t-32)/1.8)

def mtok(v):
    return (v*1.60934)

def graph_data():

    c.execute('SELECT dateTime, outTemp, windGust FROM archive \
        WHERE dateTime BETWEEN STRFTIME("%s", "2023-01-23") AND STRFTIME("%s", "2023-01-25") ')

    data = c.fetchall()
    date = []
    temperature = []
    gust = []
    for row in data:
        date.append(datetime.fromtimestamp(row[0]))
        temperature.append( ftoc(row[1]) )
        gust.append( mtok(row[2]) )

    plt.plot_date(date,temperature,'-')
    plt.plot_date(date,gust,'-')
    plt.show()

graph_data()



četrtek, 19. januar 2023 ob 20:49:04 UTC+1 je oseba mihec napisala:
Reply all
Reply to author
Forward
0 new messages