-
Notifications
You must be signed in to change notification settings - Fork 0
/
plottwo.py
90 lines (74 loc) · 2.44 KB
/
plottwo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import matplotlib.pylab as plt
import numpy as np
import datetime
import os
from pandas import read_csv
import matplotlib.dates as mdates
from pandas.plotting import register_matplotlib_converters
DATADIR = '../data'
def ticks_visual(ax,**kwarg):
'''
makes auto minor and major ticks for matplotlib figure
makes minor and major ticks thicker and longer
'''
which = kwarg.get('which','both')
from matplotlib.ticker import AutoMinorLocator
if which == 'both' or which == 'x':
ax.xaxis.set_minor_locator(AutoMinorLocator())
if which == 'both' or which == 'y':
ax.yaxis.set_minor_locator(AutoMinorLocator())
l1 = kwarg.get('l1',7)
l2 = kwarg.get('l2',4)
w1 = kwarg.get('w1',1.)
w2 = kwarg.get('w2',.8)
ax.xaxis.set_tick_params(width= w1,length = l1,which = 'major')
ax.xaxis.set_tick_params(width= w2,length = l2,which = 'minor')
ax.yaxis.set_tick_params(width= w1,length = l1,which = 'major')
ax.yaxis.set_tick_params(width= w2,length = l2,which = 'minor')
return
def grid_visual(ax, alpha = [.1,.3]):
'''
Sets grid on and adjusts the grid style.
'''
ax.grid(which = 'minor',linestyle='-', alpha = alpha[0])
ax.grid(which = 'major',linestyle='-', alpha = alpha[1])
return
def gritix(**kws):
'''
Automatically apply ticks_visual and grid_visual to the
currently active pylab axes.
'''
import matplotlib.pylab as plt
ticks_visual(plt.gca())
grid_visual(plt.gca())
return
def main():
register_matplotlib_converters()
lst = sorted([i for i in os.listdir(DATADIR) if '.txt' in i and '2020' in i])
fname = lst[-1]
fpth = os.path.join(DATADIR,fname)
data = read_csv(fpth,na_values=['nan',' nan'])
lbls = data.keys()
t = [datetime.datetime.strptime(i, '%Y/%m/%d %H:%M:%S') for i in data['time']]
nms = ['$T_1\ ^{\circ}$C','Humidity %','$T_2\ ^{\circ}$C']
for j,i in enumerate(lbls[1:]):
plt.plot(t,data[i],'-',label=nms[j])
plt.legend()
plt.gcf().autofmt_xdate()
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))
plt.gca().set_ylim(0,80)
ticks_visual(plt.gca())
grid_visual(plt.gca())
savepth = os.path.join(
os.path.expanduser('~'),
'Desktop',
fname[:-3]+'png',
)
print(f'saving to {savepth}')
plt.savefig(
savepth,
dpi=300,
bbox_inches='tight',
)
#plt.show()
main()