Skip to content

Instantly share code, notes, and snippets.

@kgantsov
Created August 24, 2014 13:05
Show Gist options
  • Save kgantsov/2926510a3848283e8e90 to your computer and use it in GitHub Desktop.
Save kgantsov/2926510a3848283e8e90 to your computer and use it in GitHub Desktop.
Gets log file of temperatures and shows it on a plot (using matplotlib)
#!/usr/bin/python
# coding: utf-8
import csv
from datetime import datetime
import matplotlib.pyplot as plt
from matplotlib import rcParams
def get_data(file_name):
time_stops = []
temps = []
with open(file_name, 'r') as data_file:
reader = csv.reader(data_file, delimiter=';', quotechar='"')
for time_stop, temp, _ in reader:
time_stops.append(datetime.strptime(time_stop, '%Y-%m-%d %H:%M:%S'))
temps.append(float(temp))
return time_stops, temps
def show_plot(time_stops, temps):
fig = plt.figure(figsize=(13, 13))
ax1 = fig.add_subplot(211)
ax1.plot(time_stops, temps, '#1abaea', label="temp")
ax1.grid(b=True, which='both', color='0.65', linestyle='-')
plt.xlabel(u'Time')
plt.ylabel(u'Temperature (ºC)')
ax1.legend(
bbox_to_anchor=(0., 1.02, 1., .102),
loc=3, ncol=2, mode="expand", borderaxespad=0.
)
plt.show()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Temperature stats')
parser.add_argument(
"-f", "--file", required=True, help="File with temperature stats"
)
args = parser.parse_args()
show_plot(*get_data(args.file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment