Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example plot program for python #27

Open
martin3000 opened this issue May 12, 2017 · 0 comments
Open

example plot program for python #27

martin3000 opened this issue May 12, 2017 · 0 comments

Comments

@martin3000
Copy link

#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from matplotlib.dates import DayLocator
from decimal import Decimal

import elitech
import datetime
from datetime import datetime
import sys
import serial
import csv

if len(sys.argv)>1: #we have command line arguments
with open(sys.argv[1], mode='r', encoding="UTF-8", newline='') as f:
reader = csv.reader(f, delimiter='\t')
data = [row for row in reader]
date = [datetime.strptime(l[1], '%Y-%m-%d %H:%M:%S') for l in data]
vals = [float(l[2]) for l in data]
else:
port = "/dev/ttyUSB0"
try:
device = elitech.Device(port)
except serial.serialutil.SerialException:
print("Device not found")
exit(8)
device.init()

get data

data = device.get_data() #get a list of tuples with number,date and temp
date=[l[1] for l in data]
vals=[l[2] for l in data]

ax=plt.axes()
ax.xaxis.set_major_formatter(dates.DateFormatter('%H:%M %d.%m.%Y'))
ax.xaxis.set_minor_locator(DayLocator())
p1 = plt.plot_date(date,vals,linestyle='solid',fmt='o')

plt.ylabel('Temp')
plt.title('Temperature')
plt.xticks(rotation=45,ha='right')
plt.grid(axis='x',which='minor')
plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant