Skip to content

Commit

Permalink
Updated plot
Browse files Browse the repository at this point in the history
Add parameter for how long to plot, fix on whole hours + timedelta.
  • Loading branch information
tmjo committed Apr 10, 2021
1 parent c59eabf commit f06b76b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/norwegiantide/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ def getNearestData(self, items, data):
except TypeError:
return None

def plot_tidedata(self, filename=None, show=False):
def plot_tidedata(
self, filename=None, show=False, xlength: timedelta = timedelta(hours=36)
):

_LOGGER.debug("Creating plot")
x = []
Expand Down Expand Up @@ -495,12 +497,14 @@ def plot_tidedata(self, filename=None, show=False):
ax.xaxis.set_major_locator(mdates.MinuteLocator(interval=120))
ax.xaxis.set_minor_locator(mdates.MinuteLocator(interval=60))
ax.tick_params(axis="x", labelsize=8)
ax.set_xlim(x[0] - timedelta(hours=1), x[-1] + timedelta(hours=1))
xstart = x[0] - timedelta(hours=1, minutes=x[0].minute)
ax.set_xlim(xstart, xstart + xlength)
ax.set(
title=f"Tide for {self.place} ({self.tide_state_full}ing)",
ylabel="Waterlevel [cm]",
)
plt.xticks(rotation=90, ha="center")
_LOGGER.debug(f"Plotting from: {xstart} to {xstart+xlength}")

# Custom scaling
ylim_min = ymin if ymin < -10 else -10
Expand Down

0 comments on commit f06b76b

Please sign in to comment.