Skip to content

Instantly share code, notes, and snippets.

@nipunbatra
Forked from milan1267/plot_data.py
Created June 16, 2013 04:47
Show Gist options
  • Save nipunbatra/5790808 to your computer and use it in GitHub Desktop.
Save nipunbatra/5790808 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import matplotlib.dates as md
import numpy as np
import datetime as dt
import time
data = np.genfromtxt('/home/milan/Projects/Summer_Project/AC/Data/data_1.csv',delimiter=',',names=['time1','date','temperature','humidity'])
#data2 = np.genfromtxt('/home/milan/Projects/Summer_Project/AC/Data/data_2.csv',delimiter=',',names=['time2','power'])
time = data['time1']
humidity = data['humidity']
temp = data['temperature']
#time2 = data2['time2']
#scaled_power = data2['power']
dates = [dt.datetime.fromtimestamp(ts) for ts in time]
#dates2 = [dt.datetime.fromtimestamp(ts2) for ts2 in time2]
datenums = md.date2num(dates)
#datenums2 = md.date2num(dates2)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(datenums,temp,'b')
ax1.set_xlabel('Date_Time')
ax1.set_ylabel('Temperature(C)', color='b')
plt.xticks( rotation=25 )
plt.yticks(np.arange(25, 32 , 0.5))
ax2 = ax1.twinx()
ax2.plot(datenums,humidity,'r')
ax2.set_xlabel('Date_Time')
ax2.set_ylabel('Humidity', color='r')
ax = plt.gca()
xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(xfmt)
plt.xticks( rotation=25 )
plt.yticks(np.arange(80, 100,10))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment