def draw_date( plot: _AxesBase, x: t.Iterable[datetime.datetime], y: t.Iterable[float], colour: t.Optional[str], ) -> None: plot.plot_date(x, y, color=colour, linestyle="-", marker="", xdate=True)
def draw_bar( plot: _AxesBase, x: t.Iterable[datetime.datetime], y: t.Iterable[float], colour: t.Optional[str], ) -> None: plot.bar(x, y, color=colour)
async def plot_sensor(config: Config[t.Any, t.Any], plot: _AxesBase, location_names: t.Dict[UUID, str], **kwargs: t.Any) -> _AxesBase: locations = [] if config.get_data is None: raise ValueError("You must provide a get_data function") async for deployment_id, query_results in config.get_data(**kwargs): if deployment_id == GLOBAL: name = "Global" else: try: deployment = await get_deployment_by_id(deployment_id) except IndexError: name = str(deployment_id) colour = None else: name = deployment.name or str(deployment_id) colour = deployment.colour # Mypy currently doesn't understand callable fields on datatypes: https://github.com/python/mypy/issues/5485 points = [dp async for dp in config.clean(query_results)] # type: ignore if not points: continue locations.append(name) x, y = zip(*points) plot.set_title(config.title) plot.set_ylabel(config.ylabel) if config.draw is None: raise ValueError("You must provide a get_data function") config.draw(plot, x, y, colour) plot.legend(locations) return plot
async def plot_sensor(config: Config, plot: _AxesBase, location_names: t.Dict[UUID, str], **kwargs): locations = [] async for deployment, query_results in get_data_by_deployment( sensor_name=config.sensor_name, **kwargs): # Mypy currently doesn't understand callable fields on datatypes: https://github.com/python/mypy/issues/5485 points = [dp async for dp in config.clean(query_results)] # type: ignore if not points: continue locations.append(deployment) x, y = zip(*points) plot.set_title(config.title) plot.set_ylabel(config.ylabel) plot.plot_date(x, y, f"-", xdate=True) plot.legend([location_names.get(l, l) for l in locations]) return plot
def draw_map( plot: _AxesBase, x: t.Iterable[t.Tuple[float, float]], y: t.Iterable[float], colour: t.Optional[str], ) -> None: lon = [merc_y(coord[0]) for coord in x] lat = [merc_x(coord[1]) for coord in x] for axis in "x", "y": plt.tick_params( axis=axis, which="both", bottom=False, top=False, left=False, right=False, labelbottom=False, labelleft=False, ) plot.tricontourf(lat, lon, y) plot.plot(lat, lon, "wo", ms=3) plot.set_aspect(1.0)