def plot_ghi_curves( clearsky_ghi: np.ndarray, station_ghi: np.ndarray, pred_ghi: typing.Optional[np.ndarray], window_start: datetime.datetime, window_end: datetime.datetime, sample_step: datetime.timedelta, horiz_offset: datetime.timedelta, ax: plt.Axes, station_name: typing.Optional[typing.AnyStr] = None, station_color: typing.Optional[typing.AnyStr] = None, current_time: typing.Optional[datetime.datetime] = None, ) -> plt.Axes: """Plots a set of GHI curves and returns the associated matplotlib axes object. This function is used in ``draw_daily_ghi`` and ``preplot_live_ghi_curves`` to create simple graphs of GHI curves (clearsky, measured, predicted). """ assert clearsky_ghi.ndim == 1 and station_ghi.ndim == 1 and clearsky_ghi.size == station_ghi.size assert pred_ghi is None or (pred_ghi.ndim == 1 and clearsky_ghi.size == pred_ghi.size) hour_tick_locator = matplotlib.dates.HourLocator(interval=4) minute_tick_locator = matplotlib.dates.HourLocator(interval=1) datetime_fmt = matplotlib.dates.DateFormatter("%H:%M") datetime_range = pd.date_range(window_start, window_end, freq=sample_step) xrange_real = matplotlib.dates.date2num( [d.to_pydatetime() for d in datetime_range]) if current_time is not None: ax.axvline(x=matplotlib.dates.date2num(current_time), color="r", label="current") station_name = f"measured ({station_name})" if station_name else "measured" ax.plot(xrange_real, clearsky_ghi, ":", label="clearsky") if station_color is not None: ax.plot(xrange_real, station_ghi, linestyle="solid", color=station_color, label=station_name) else: ax.plot(xrange_real, station_ghi, linestyle="solid", label=station_name) datetime_range = pd.date_range(window_start + horiz_offset, window_end + horiz_offset, freq=sample_step) xrange_offset = matplotlib.dates.date2num( [d.to_pydatetime() for d in datetime_range]) if pred_ghi is not None: ax.plot(xrange_offset, pred_ghi, ".-", label="predicted") ax.xaxis.set_major_locator(hour_tick_locator) ax.xaxis.set_major_formatter(datetime_fmt) ax.xaxis.set_minor_locator(minute_tick_locator) hour_offset = datetime.timedelta(hours=1) // sample_step ax.set_xlim(xrange_real[hour_offset - 1], xrange_real[-hour_offset + 1]) ax.format_xdata = matplotlib.dates.DateFormatter("%Y-%m-%d %H:%M") ax.grid(True) return ax