seems to be working, but matplotlib display is acting weird
This commit is contained in:
@@ -3,7 +3,7 @@ from contextlib import suppress
|
||||
from dataclasses import InitVar, dataclass, field
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, Iterable
|
||||
|
||||
W
|
||||
import astral
|
||||
import matplotlib.dates as mdates
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -16,7 +16,7 @@ HOME_TZ = datetime.now().astimezone().tzinfo
|
||||
|
||||
def format_x_axis(fig):
|
||||
ax: plt.Axes = fig.axes[0]
|
||||
# ax.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0, 24, 2)))
|
||||
ax.xaxis.set_major_locator(mdates.HourLocator(byhour=range(0, 24, 2)))
|
||||
ax.xaxis.set_major_formatter(mdates.DateFormatter('%I%p'))
|
||||
ax.grid(True)
|
||||
fig.autofmt_xdate()
|
||||
@@ -57,9 +57,9 @@ def parse_periods(observer: Observer, periods: Dict):
|
||||
datetime.strptime(period['time'], '%I:%M:%S%p').time()
|
||||
).astimezone()
|
||||
|
||||
res = {'time': time.replace(tzinfo=None)}
|
||||
# res = {'time': time.replace(tzinfo=None)}
|
||||
# res = {'time': time.replace(tzinfo=HOME_TZ)}
|
||||
# res = {'time': time}
|
||||
res = {'time': time}
|
||||
res.update({k: period[k] for k in ['brightness', 'color_temp'] if k in period})
|
||||
yield res
|
||||
|
||||
@@ -82,27 +82,24 @@ class DaylightAdjuster:
|
||||
tz=HOME_TZ
|
||||
)
|
||||
|
||||
pytimes = [dt.to_pydatetime() for dt in times]
|
||||
pytimes = (dt.to_pydatetime() for dt in times)
|
||||
|
||||
el = pd.Series(
|
||||
(elevation(self.observer, dt) for dt in pytimes),
|
||||
times, name='elevation'
|
||||
index=times, name='elevation'
|
||||
)
|
||||
|
||||
# el.index = el.index.tz_convert(HOME_TZ)
|
||||
# el.index = el.index.tz_convert(None)
|
||||
|
||||
self.df = pd.DataFrame(el)
|
||||
|
||||
# self.df = pd.concat([
|
||||
# pd.DataFrame(parse_periods(self.observer, periods)).set_index('time'),
|
||||
# el
|
||||
# ], axis=1).sort_index().interpolate().bfill().ffill()
|
||||
# self.df = pd.DataFrame(el)
|
||||
self.df = pd.concat([
|
||||
pd.DataFrame(parse_periods(self.observer, periods)).set_index('time'),
|
||||
el
|
||||
], axis=1).sort_index().interpolate().bfill().ffill()
|
||||
|
||||
# self.df.index = self.df.index.to_series().dt.tz_localize(None)
|
||||
|
||||
# print('Done making daylight_adjuster')
|
||||
|
||||
@property
|
||||
def observer(self) -> astral.Observer:
|
||||
return astral.Observer(self.latitude, self.longitude)
|
||||
@@ -120,15 +117,17 @@ class DaylightAdjuster:
|
||||
format_x_axis(fig)
|
||||
ax.set_xlim(self.df.index[0], self.df.index[-1])
|
||||
|
||||
# ax.xaxis_date(HOME_TZ)
|
||||
|
||||
ax2 = ax.twinx()
|
||||
# handles.extend(ax2.plot(normalize(self.df['brightness'], 1, 255), 'tab:orange'))
|
||||
# handles.extend(ax2.plot(normalize(self.df['color_temp'], 1, 255), 'tab:green'))
|
||||
handles.extend(ax2.plot(normalize(self.df['brightness'], 1, 255), 'tab:orange'))
|
||||
handles.extend(ax2.plot(normalize(self.df['color_temp'], 150, 650), 'tab:green'))
|
||||
ax2.set_ylabel('Brightness')
|
||||
ax2.set_ylim(0, 100)
|
||||
|
||||
# handles.append(ax.axvline(datetime.now(),
|
||||
# linestyle='--',
|
||||
# color='g'))
|
||||
handles.append(ax.axvline(datetime.now(),
|
||||
linestyle='--',
|
||||
color='g'))
|
||||
|
||||
# handles.append(ax2.axhline(self.get_brightness(),
|
||||
# linestyle='--',
|
||||
|
||||
Reference in New Issue
Block a user