plot

hydrostats.visual.plot(merged_data_df, legend=('Simulated Data', 'Observed Data'), metrics=None, grid=False, title=None, x_season=False, labels=None, linestyles=('ro', 'b^'), tight_xlim=False, fig_size=(10, 6), text_adjust=(-0.35, 0.75), plot_adjust=0.27, transparency=0.5, ebars=None, ecolor=None, markersize=2, errorevery=1, markevery=1)

Create a comparison time series line plot of simulated and observed time series data.

The time series plot is a function that is available for viewing two times series plotted side by side vs. time. Goodness of fit metrics can also be viewed on the plot to compare the two time series.

Parameters:
  • merged_data_df (DataFrame) – DataFrame must contain datetime index and floating point type numbers in the two columns. The left columns must be simulated data and the right column observed data.
  • legend (tuple of str) – Adds a Legend in the ‘best’ location determined by matplotlib. The entries in the tuple describe the left and right columns of the merged_data_df data.
  • metrics (list of str) – Adds Metrics to the left side of the plot. Any metric from the Hydrostats library can be added to the plot as the abbreviation of the function. The entries must be in a list. (e.g. [‘ME’, ‘r2’, ‘KGE (2012)’]).
  • grid (bool) – If True, adds a grid to the plot.
  • title (str) – If given, adds a title to the plot.
  • x_season (bool) – If True, the x-axis ticks will be monthly. This is a useful feature when plotting seasonal time series comparisons (e.g. daily averages).
  • labels (list of str) – List of two str type inputs specifying x-axis labels and y-axis labels, respectively.
  • linestyles (list of str) – List of two string type inputs thet will change the linestyle of the predicted and recorded data, respectively. Linestyle references can be found in Matplotlib Linestyles Help.
  • tight_xlim (bool) – If true, will set the padding to zero for the lines in the line plot.
  • fig_size (tuple of floats) – Tuple of length two that specifies the horizontal and vertical lengths of the plot in inches, respectively.
  • text_adjust (tuple) – Tuple of length two with float type inputs indicating the relative position of the text (x-coordinate, y-coordinate) when adding metrics to the plot.
  • plot_adjust (float) – Specifies the relative position to shift the plot the the right when adding metrics to the plot.
  • transparency (float) – Value between 0 to 1 indicating the transparency of the two lines that are plotted and error bars if they are plotted, lower means more transparent.
  • ebars (DataFrame) – DataFrame must contain datetime index and two columns of data that specify the error of the plots, with the simulated error on the left and the observed error on the right. These dataframes can be created with the daily_std_error, daily_std_dev, monthly_std_error, and monthly_std_dev functions.
  • ecolor (tuple of str) – Tuple of two sting type inputs specifying the colors of the errorbars (e.g. [‘r’, ‘k’] would make red and black errorbars on the simulated and observed data, respectively).
  • markersize (float) – Indicates the size of the markers on the plot, if markers are used.
  • errorevery (int) – Specifies how often to put error bars on the plot.
  • markevery (int) – Specifies how often to put markers on the plot if markers are used.
Returns:

fig – A matplotlib figure handle is returned, which can be viewed with the matplotlib.pyplot.show() command.

Return type:

Matplotlib figure instance

Examples

In this example two models are compared.

>>> import hydrostats.data as hd
>>> import hydrostats.visual as hv
>>> import matplotlib.pyplot as plt
>>> sfpt_url = r'https://github.com/waderoberts123/Hydrostats/raw/master/Sample_data/sfpt_data/magdalena-calamar_interim_data.csv'
>>> glofas_url = r'https://github.com/waderoberts123/Hydrostats/raw/master/Sample_data/GLOFAS_Data/magdalena-calamar_ECMWF_data.csv'
>>> merged_df = hd.merge_data(sfpt_url, glofas_url, column_names=('SFPT', 'GLOFAS'))
>>> seasonal_df = hd.seasonal_period(merged_df, ('04-01', '07-31'), time_range=('1986-01-01', '1992-12-31'))
>>> daily_avg_df = hd.daily_average(merged_data=merged_df)  # Seasonal Daily Averages
>>> daily_std_error = hd.daily_std_error(merged_data=merged_df)  # Seasonal Daily Standard Deviation

The entire timeseries is plotted below

>>> plot(merged_data_df=merged_df,
>>>      title='Hydrograph of Entire Time Series',
>>>      linestyles=['r-', 'k-'],
>>>      legend=('SFPT', 'GLOFAS'),
>>>      labels=['Datetime', 'Streamflow (cfs)'],
>>>      metrics=['ME', 'NSE', 'SA'],
>>>      grid=True)
>>> plt.show()
../_images/plot_full1.png

The seasonal averages with standard error bars is plotted below

>>> plot(merged_data_df=daily_avg_df,
>>>      title='Daily Average Streamflow (Standard Error)',
>>>      legend=('SFPT', 'GLOFAS'),
>>>      x_season=True,
>>>      labels=['Datetime', 'Streamflow (csm)'],
>>>      linestyles=['r-', 'k-'],
>>>      fig_size=(14, 8),
>>>      ebars=daily_std_error,
>>>      ecolor=('r', 'k'),
>>>      tight_xlim=True
>>>      )
>>> plt.show()
../_images/plot_seasonal.png