We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pandas-lag-plotting
Added pandas style lag plotting for a single lag as well as a list of lags

<!--
Thanks for contributing a pull request! Please ensure you have taken a look at our contribution guide: https://github.com/alan-turing-institute/sktime/blob/master/CONTRIBUTING.md
-->

#### Reference Issues/PRs
<!--
Example: Fixes #1234. See also #3456.

Please use keywords (e.g., Fixes) to create link to the issues or pull requests
you resolved, so that they will automatically be closed when your pull request
is merged. See https://github.com/blog/1506-closing-issues-via-pull-requests
-->
Pandas-style lag plotting for sktime #588
https://github.com/alan-turing-institute/sktime/issues/588 

#### What does this implement/fix? Explain your changes.
<!--
A clear and concise description of what you have implemented.
-->

A utility for plotting lagged versions of a time series.
It allows plotting several such lagged versions together using 
the pandas lag_plot api which natively allows only one plot at
a particular lag.  


#### Does your contribution introduce a new dependency? If yes, which one?

<!--
If your contribution does add a new hard dependency, we may suggest to initially develop your contribution in a separate companion package in https://github.com/sktime/ to keep external dependencies of the core sktime package to a minimum.
-->

None, that I can think of.

#### What should a reviewer concentrate their feedback on?

<!-- This section is particularly useful if you have a pull request that is still in development. You can guide the reviews to focus on the parts that are ready for their comments. We suggest using bullets (indicated by * or -) and filled checkboxes [x] here -->

#### Any other comments?
<!--
Please be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process.
-->

Here is a demo of this utility in a collaboratory notebook: https://colab.research.google.com/drive/1tbHVqTZwGkeRjunvqGV-6Ql7NLjVJJvs?usp=sharing 

#### PR checklist
<!--
Please go through the checklist below. Please feel free to remove points if they are not applicable.
-->

##### For all contributions
- [x] I've added myself to the [list of contributors](https://github.com/alan-turing-institute/sktime/blob/master/.all-contributorsrc).
- [x] Optionally, I've updated sktime's [CODEOWNERS](https://github.com/alan-turing-institute/sktime/blob/master/CODEOWNERS) to receive notifications about future changes to these files.
- [x] I've added unit tests and made sure they pass locally.

##### For new estimators
- [x] I've added the estimator to the online documentation.
- [x] I've updated the existing example notebooks or provided a new one to showcase how my estimator works.


<!--
Thanks for contributing!
-->


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sktime/utils/plotting.py`
Content:
```
1 #!/usr/bin/env python3 -u
2 # -*- coding: utf-8 -*-
3 # copyright: sktime developers, BSD-3-Clause License (see LICENSE file)
4 """Common timeseries plotting functionality.
5 
6 Functions
7 ---------
8 plot_series(*series, labels=None, markers=None, ax=None)
9 plot_correlations(
10     series,
11     lags=24,
12     alpha=0.05,
13     zero_lag=True,
14     acf_fft=False,
15     acf_adjusted=True,
16     pacf_method="ywadjusted",
17     suptitle=None,
18     series_title=None,
19     acf_title="Autocorrelation",
20     pacf_title="Partial Autocorrelation",
21 )
22 """
23 __all__ = ["plot_series", "plot_correlations"]
24 __author__ = ["Markus Löning", "Ryan Kuhns", "Drishti Bhasin"]
25 
26 import numpy as np
27 
28 from sktime.utils.validation._dependencies import _check_soft_dependencies
29 from sktime.utils.validation.forecasting import check_y
30 from sktime.utils.validation.series import check_consistent_index_type
31 
32 from statsmodels.graphics.tsaplots import plot_acf, plot_pacf
33 
34 from sktime.datatypes import convert_to
35 
36 
37 def plot_series(
38     *series, labels=None, markers=None, x_label=None, y_label=None, ax=None
39 ):
40     """Plot one or more time series.
41 
42     Parameters
43     ----------
44     series : pd.Series or iterable of pd.Series
45         One or more time series
46     labels : list, default = None
47         Names of series, will be displayed in figure legend
48     markers: list, default = None
49         Markers of data points, if None the marker "o" is used by default.
50         The length of the list has to match with the number of series.
51 
52     Returns
53     -------
54     fig : plt.Figure
55     ax : plt.Axis
56     """
57     _check_soft_dependencies("matplotlib", "seaborn")
58     import matplotlib.pyplot as plt
59     from matplotlib.ticker import FuncFormatter, MaxNLocator
60     from matplotlib.cbook import flatten
61     import seaborn as sns
62 
63     for y in series:
64         check_y(y)
65 
66     series = list(series)
67     series = [convert_to(y, "pd.Series", "Series") for y in series]
68 
69     n_series = len(series)
70     _ax_kwarg_is_none = True if ax is None else False
71     # labels
72     if labels is not None:
73         if n_series != len(labels):
74             raise ValueError(
75                 """There must be one label for each time series,
76                 but found inconsistent numbers of series and
77                 labels."""
78             )
79         legend = True
80     else:
81         labels = ["" for _ in range(n_series)]
82         legend = False
83 
84     # markers
85     if markers is not None:
86         if n_series != len(markers):
87             raise ValueError(
88                 """There must be one marker for each time series,
89                 but found inconsistent numbers of series and
90                 markers."""
91             )
92     else:
93         markers = ["o" for _ in range(n_series)]
94 
95     # create combined index
96     index = series[0].index
97     for y in series[1:]:
98         # check index types
99         check_consistent_index_type(index, y.index)
100         index = index.union(y.index)
101 
102     # generate integer x-values
103     xs = [np.argwhere(index.isin(y.index)).ravel() for y in series]
104 
105     # create figure if no Axe provided for plotting
106     if _ax_kwarg_is_none:
107         fig, ax = plt.subplots(1, figsize=plt.figaspect(0.25))
108 
109     colors = sns.color_palette("colorblind", n_colors=n_series)
110 
111     # plot series
112     for x, y, color, label, marker in zip(xs, series, colors, labels, markers):
113 
114         # scatter if little data is available or index is not complete
115         if len(x) <= 3 or not np.array_equal(np.arange(x[0], x[-1] + 1), x):
116             plot_func = sns.scatterplot
117         else:
118             plot_func = sns.lineplot
119 
120         plot_func(x=x, y=y, ax=ax, marker=marker, label=label, color=color)
121 
122     # combine data points for all series
123     xs_flat = list(flatten(xs))
124 
125     # set x label of data point to the matching index
126     def format_fn(tick_val, tick_pos):
127         if int(tick_val) in xs_flat:
128             return index[int(tick_val)]
129         else:
130             return ""
131 
132     # dynamically set x label ticks and spacing from index labels
133     ax.xaxis.set_major_formatter(FuncFormatter(format_fn))
134     ax.xaxis.set_major_locator(MaxNLocator(integer=True))
135 
136     # Label the x and y axes
137     if x_label is not None:
138         ax.set_xlabel(x_label)
139 
140     _y_label = y_label if y_label is not None else series[0].name
141     ax.set_ylabel(_y_label)
142 
143     if legend:
144         ax.legend()
145     if _ax_kwarg_is_none:
146         return fig, ax
147     else:
148         return ax
149 
150 
151 def plot_correlations(
152     series,
153     lags=24,
154     alpha=0.05,
155     zero_lag=True,
156     acf_fft=False,
157     acf_adjusted=True,
158     pacf_method="ywadjusted",
159     suptitle=None,
160     series_title=None,
161     acf_title="Autocorrelation",
162     pacf_title="Partial Autocorrelation",
163 ):
164     """Plot series and its ACF and PACF values.
165 
166     Parameters
167     ----------
168     series : pd.Series
169         A time series.
170 
171     lags : int, default = 24
172         Number of lags to include in ACF and PACF plots
173 
174     alpha : int, default = 0.05
175         Alpha value used to set confidence intervals. Alpha = 0.05 results in
176         95% confidence interval with standard deviation calculated via
177         Bartlett's formula.
178 
179     zero_lag : bool, default = True
180         If True, start ACF and PACF plots at 0th lag
181 
182     acf_fft : bool,  = False
183         Whether to compute ACF via FFT.
184 
185     acf_adjusted : bool, default = True
186         If True, denonimator of ACF calculations uses n-k instead of n, where
187         n is number of observations and k is the lag.
188 
189     pacf_method : str, default = 'ywadjusted'
190         Method to use in calculation of PACF.
191 
192     suptitle : str, default = None
193         The text to use as the Figure's suptitle.
194 
195     series_title : str, default = None
196         Used to set the title of the series plot if provided. Otherwise, series
197         plot has no title.
198 
199     acf_title : str, default = 'Autocorrelation'
200         Used to set title of ACF plot.
201 
202     pacf_title : str, default = 'Partial Autocorrelation'
203         Used to set title of PACF plot.
204 
205     Returns
206     -------
207     fig : matplotlib.figure.Figure
208 
209     axes : np.ndarray
210         Array of the figure's Axe objects
211     """
212     _check_soft_dependencies("matplotlib")
213     import matplotlib.pyplot as plt
214 
215     series = check_y(series)
216     series = convert_to(series, "pd.Series", "Series")
217 
218     # Setup figure for plotting
219     fig = plt.figure(constrained_layout=True, figsize=(12, 8))
220     gs = fig.add_gridspec(2, 2)
221     f_ax1 = fig.add_subplot(gs[0, :])
222     if series_title is not None:
223         f_ax1.set_title(series_title)
224     f_ax2 = fig.add_subplot(gs[1, 0])
225     f_ax3 = fig.add_subplot(gs[1, 1])
226 
227     # Create expected plots on their respective Axes
228     plot_series(series, ax=f_ax1)
229     plot_acf(
230         series,
231         ax=f_ax2,
232         lags=lags,
233         zero=zero_lag,
234         alpha=alpha,
235         title=acf_title,
236         adjusted=acf_adjusted,
237         fft=acf_fft,
238     )
239     plot_pacf(
240         series,
241         ax=f_ax3,
242         lags=lags,
243         zero=zero_lag,
244         alpha=alpha,
245         title=pacf_title,
246         method=pacf_method,
247     )
248     if suptitle is not None:
249         fig.suptitle(suptitle, size="xx-large")
250 
251     return fig, np.array(fig.get_axes())
252
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sktime/utils/plotting.py b/sktime/utils/plotting.py
--- a/sktime/utils/plotting.py
+++ b/sktime/utils/plotting.py
@@ -1,29 +1,15 @@
 #!/usr/bin/env python3 -u
 # -*- coding: utf-8 -*-
 # copyright: sktime developers, BSD-3-Clause License (see LICENSE file)
-"""Common timeseries plotting functionality.
+"""Common timeseries plotting functionality."""
 
-Functions
----------
-plot_series(*series, labels=None, markers=None, ax=None)
-plot_correlations(
-    series,
-    lags=24,
-    alpha=0.05,
-    zero_lag=True,
-    acf_fft=False,
-    acf_adjusted=True,
-    pacf_method="ywadjusted",
-    suptitle=None,
-    series_title=None,
-    acf_title="Autocorrelation",
-    pacf_title="Partial Autocorrelation",
-)
-"""
 __all__ = ["plot_series", "plot_correlations"]
-__author__ = ["Markus Löning", "Ryan Kuhns", "Drishti Bhasin"]
+__author__ = ["mloning", "RNKuhns", "Drishti Bhasin"]
+
+import math
 
 import numpy as np
+import pandas as pd
 
 from sktime.utils.validation._dependencies import _check_soft_dependencies
 from sktime.utils.validation.forecasting import check_y
@@ -148,6 +134,79 @@
         return ax
 
 
+def plot_lags(series, lags=1, suptitle=None):
+    """Plot one or more lagged versions of a time series.
+
+    Parameters
+    ----------
+    series : pd.Series
+        Time series for plotting lags.
+    lags : int or array-like, default=1
+        The lag or lags to plot.
+
+        - int plots the specified lag
+        - array-like  plots specified lags in the array/list
+
+    suptitle : str, default=None
+        The text to use as the Figure's suptitle. If None, then the title
+        will be "Plot of series against lags {lags}"
+
+    Returns
+    -------
+    fig : matplotlib.figure.Figure
+
+    axes : np.ndarray
+        Array of the figure's Axe objects
+
+    Examples
+    --------
+    >>> from sktime.datasets import load_airline
+    >>> y = load_airline()
+    >>> fig, ax = plot_lags(y, lags=2) # plot of y(t) with y(t-2)
+    >>> fig, ax = plot_lags(y, lags=[1,2,3]) # plots of y(t) with y(t-1),y(t-2)..
+    """
+    _check_soft_dependencies("matplotlib")
+    import matplotlib.pyplot as plt
+
+    check_y(series)
+
+    if isinstance(lags, int):
+        single_lag = True
+        lags = [lags]
+    elif isinstance(lags, (tuple, list, np.ndarray)):
+        single_lag = False
+    else:
+        raise ValueError("`lags should be an integer, tuple, list, or np.ndarray.")
+
+    length = len(lags)
+    n_cols = min(3, length)
+    n_rows = math.ceil(length / n_cols)
+    fig, ax = plt.subplots(
+        nrows=n_rows,
+        ncols=n_cols,
+        figsize=(8, 6 * n_rows),
+        sharex=True,
+        sharey=True,
+    )
+    if single_lag:
+        axes = ax
+        pd.plotting.lag_plot(series, lag=lags[0], ax=axes)
+    else:
+        axes = ax.ravel()
+        for i, val in enumerate(lags):
+            pd.plotting.lag_plot(series, lag=val, ax=axes[i])
+
+    if suptitle is None:
+        fig.suptitle(
+            f"Plot of series against lags {', '.join([str(lag) for lag in lags])}",
+            size="xx-large",
+        )
+    else:
+        fig.suptitle(suptitle, size="xx-large")
+
+    return fig, np.array(fig.get_axes())
+
+
 def plot_correlations(
     series,
     lags=24,

{"golden_diff": "diff --git a/sktime/utils/plotting.py b/sktime/utils/plotting.py\n--- a/sktime/utils/plotting.py\n+++ b/sktime/utils/plotting.py\n@@ -1,29 +1,15 @@\n #!/usr/bin/env python3 -u\n # -*- coding: utf-8 -*-\n # copyright: sktime developers, BSD-3-Clause License (see LICENSE file)\n-\"\"\"Common timeseries plotting functionality.\n+\"\"\"Common timeseries plotting functionality.\"\"\"\n \n-Functions\n----------\n-plot_series(*series, labels=None, markers=None, ax=None)\n-plot_correlations(\n-    series,\n-    lags=24,\n-    alpha=0.05,\n-    zero_lag=True,\n-    acf_fft=False,\n-    acf_adjusted=True,\n-    pacf_method=\"ywadjusted\",\n-    suptitle=None,\n-    series_title=None,\n-    acf_title=\"Autocorrelation\",\n-    pacf_title=\"Partial Autocorrelation\",\n-)\n-\"\"\"\n __all__ = [\"plot_series\", \"plot_correlations\"]\n-__author__ = [\"Markus L\u00f6ning\", \"Ryan Kuhns\", \"Drishti Bhasin\"]\n+__author__ = [\"mloning\", \"RNKuhns\", \"Drishti Bhasin\"]\n+\n+import math\n \n import numpy as np\n+import pandas as pd\n \n from sktime.utils.validation._dependencies import _check_soft_dependencies\n from sktime.utils.validation.forecasting import check_y\n@@ -148,6 +134,79 @@\n         return ax\n \n \n+def plot_lags(series, lags=1, suptitle=None):\n+    \"\"\"Plot one or more lagged versions of a time series.\n+\n+    Parameters\n+    ----------\n+    series : pd.Series\n+        Time series for plotting lags.\n+    lags : int or array-like, default=1\n+        The lag or lags to plot.\n+\n+        - int plots the specified lag\n+        - array-like  plots specified lags in the array/list\n+\n+    suptitle : str, default=None\n+        The text to use as the Figure's suptitle. If None, then the title\n+        will be \"Plot of series against lags {lags}\"\n+\n+    Returns\n+    -------\n+    fig : matplotlib.figure.Figure\n+\n+    axes : np.ndarray\n+        Array of the figure's Axe objects\n+\n+    Examples\n+    --------\n+    >>> from sktime.datasets import load_airline\n+    >>> y = load_airline()\n+    >>> fig, ax = plot_lags(y, lags=2) # plot of y(t) with y(t-2)\n+    >>> fig, ax = plot_lags(y, lags=[1,2,3]) # plots of y(t) with y(t-1),y(t-2)..\n+    \"\"\"\n+    _check_soft_dependencies(\"matplotlib\")\n+    import matplotlib.pyplot as plt\n+\n+    check_y(series)\n+\n+    if isinstance(lags, int):\n+        single_lag = True\n+        lags = [lags]\n+    elif isinstance(lags, (tuple, list, np.ndarray)):\n+        single_lag = False\n+    else:\n+        raise ValueError(\"`lags should be an integer, tuple, list, or np.ndarray.\")\n+\n+    length = len(lags)\n+    n_cols = min(3, length)\n+    n_rows = math.ceil(length / n_cols)\n+    fig, ax = plt.subplots(\n+        nrows=n_rows,\n+        ncols=n_cols,\n+        figsize=(8, 6 * n_rows),\n+        sharex=True,\n+        sharey=True,\n+    )\n+    if single_lag:\n+        axes = ax\n+        pd.plotting.lag_plot(series, lag=lags[0], ax=axes)\n+    else:\n+        axes = ax.ravel()\n+        for i, val in enumerate(lags):\n+            pd.plotting.lag_plot(series, lag=val, ax=axes[i])\n+\n+    if suptitle is None:\n+        fig.suptitle(\n+            f\"Plot of series against lags {', '.join([str(lag) for lag in lags])}\",\n+            size=\"xx-large\",\n+        )\n+    else:\n+        fig.suptitle(suptitle, size=\"xx-large\")\n+\n+    return fig, np.array(fig.get_axes())\n+\n+\n def plot_correlations(\n     series,\n     lags=24,\n", "issue": "pandas-lag-plotting\nAdded pandas style lag plotting for a single lag as well as a list of lags\r\n\r\n<!--\r\nThanks for contributing a pull request! Please ensure you have taken a look at our contribution guide: https://github.com/alan-turing-institute/sktime/blob/master/CONTRIBUTING.md\r\n-->\r\n\r\n#### Reference Issues/PRs\r\n<!--\r\nExample: Fixes #1234. See also #3456.\r\n\r\nPlease use keywords (e.g., Fixes) to create link to the issues or pull requests\r\nyou resolved, so that they will automatically be closed when your pull request\r\nis merged. See https://github.com/blog/1506-closing-issues-via-pull-requests\r\n-->\r\nPandas-style lag plotting for sktime #588\r\nhttps://github.com/alan-turing-institute/sktime/issues/588 \r\n\r\n#### What does this implement/fix? Explain your changes.\r\n<!--\r\nA clear and concise description of what you have implemented.\r\n-->\r\n\r\nA utility for plotting lagged versions of a time series.\r\nIt allows plotting several such lagged versions together using \r\nthe pandas lag_plot api which natively allows only one plot at\r\na particular lag.  \r\n\r\n\r\n#### Does your contribution introduce a new dependency? If yes, which one?\r\n\r\n<!--\r\nIf your contribution does add a new hard dependency, we may suggest to initially develop your contribution in a separate companion package in https://github.com/sktime/ to keep external dependencies of the core sktime package to a minimum.\r\n-->\r\n\r\nNone, that I can think of.\r\n\r\n#### What should a reviewer concentrate their feedback on?\r\n\r\n<!-- This section is particularly useful if you have a pull request that is still in development. You can guide the reviews to focus on the parts that are ready for their comments. We suggest using bullets (indicated by * or -) and filled checkboxes [x] here -->\r\n\r\n#### Any other comments?\r\n<!--\r\nPlease be aware that we are a loose team of volunteers so patience is necessary; assistance handling other issues is very welcome. We value all user contributions, no matter how minor they are. If we are slow to review, either the pull request needs some benchmarking, tinkering, convincing, etc. or more likely the reviewers are simply busy. In either case, we ask for your understanding during the review process.\r\n-->\r\n\r\nHere is a demo of this utility in a collaboratory notebook: https://colab.research.google.com/drive/1tbHVqTZwGkeRjunvqGV-6Ql7NLjVJJvs?usp=sharing \r\n\r\n#### PR checklist\r\n<!--\r\nPlease go through the checklist below. Please feel free to remove points if they are not applicable.\r\n-->\r\n\r\n##### For all contributions\r\n- [x] I've added myself to the [list of contributors](https://github.com/alan-turing-institute/sktime/blob/master/.all-contributorsrc).\r\n- [x] Optionally, I've updated sktime's [CODEOWNERS](https://github.com/alan-turing-institute/sktime/blob/master/CODEOWNERS) to receive notifications about future changes to these files.\r\n- [x] I've added unit tests and made sure they pass locally.\r\n\r\n##### For new estimators\r\n- [x] I've added the estimator to the online documentation.\r\n- [x] I've updated the existing example notebooks or provided a new one to showcase how my estimator works.\r\n\r\n\r\n<!--\r\nThanks for contributing!\r\n-->\r\n\n", "before_files": [{"content": "#!/usr/bin/env python3 -u\n# -*- coding: utf-8 -*-\n# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)\n\"\"\"Common timeseries plotting functionality.\n\nFunctions\n---------\nplot_series(*series, labels=None, markers=None, ax=None)\nplot_correlations(\n    series,\n    lags=24,\n    alpha=0.05,\n    zero_lag=True,\n    acf_fft=False,\n    acf_adjusted=True,\n    pacf_method=\"ywadjusted\",\n    suptitle=None,\n    series_title=None,\n    acf_title=\"Autocorrelation\",\n    pacf_title=\"Partial Autocorrelation\",\n)\n\"\"\"\n__all__ = [\"plot_series\", \"plot_correlations\"]\n__author__ = [\"Markus L\u00f6ning\", \"Ryan Kuhns\", \"Drishti Bhasin\"]\n\nimport numpy as np\n\nfrom sktime.utils.validation._dependencies import _check_soft_dependencies\nfrom sktime.utils.validation.forecasting import check_y\nfrom sktime.utils.validation.series import check_consistent_index_type\n\nfrom statsmodels.graphics.tsaplots import plot_acf, plot_pacf\n\nfrom sktime.datatypes import convert_to\n\n\ndef plot_series(\n    *series, labels=None, markers=None, x_label=None, y_label=None, ax=None\n):\n    \"\"\"Plot one or more time series.\n\n    Parameters\n    ----------\n    series : pd.Series or iterable of pd.Series\n        One or more time series\n    labels : list, default = None\n        Names of series, will be displayed in figure legend\n    markers: list, default = None\n        Markers of data points, if None the marker \"o\" is used by default.\n        The length of the list has to match with the number of series.\n\n    Returns\n    -------\n    fig : plt.Figure\n    ax : plt.Axis\n    \"\"\"\n    _check_soft_dependencies(\"matplotlib\", \"seaborn\")\n    import matplotlib.pyplot as plt\n    from matplotlib.ticker import FuncFormatter, MaxNLocator\n    from matplotlib.cbook import flatten\n    import seaborn as sns\n\n    for y in series:\n        check_y(y)\n\n    series = list(series)\n    series = [convert_to(y, \"pd.Series\", \"Series\") for y in series]\n\n    n_series = len(series)\n    _ax_kwarg_is_none = True if ax is None else False\n    # labels\n    if labels is not None:\n        if n_series != len(labels):\n            raise ValueError(\n                \"\"\"There must be one label for each time series,\n                but found inconsistent numbers of series and\n                labels.\"\"\"\n            )\n        legend = True\n    else:\n        labels = [\"\" for _ in range(n_series)]\n        legend = False\n\n    # markers\n    if markers is not None:\n        if n_series != len(markers):\n            raise ValueError(\n                \"\"\"There must be one marker for each time series,\n                but found inconsistent numbers of series and\n                markers.\"\"\"\n            )\n    else:\n        markers = [\"o\" for _ in range(n_series)]\n\n    # create combined index\n    index = series[0].index\n    for y in series[1:]:\n        # check index types\n        check_consistent_index_type(index, y.index)\n        index = index.union(y.index)\n\n    # generate integer x-values\n    xs = [np.argwhere(index.isin(y.index)).ravel() for y in series]\n\n    # create figure if no Axe provided for plotting\n    if _ax_kwarg_is_none:\n        fig, ax = plt.subplots(1, figsize=plt.figaspect(0.25))\n\n    colors = sns.color_palette(\"colorblind\", n_colors=n_series)\n\n    # plot series\n    for x, y, color, label, marker in zip(xs, series, colors, labels, markers):\n\n        # scatter if little data is available or index is not complete\n        if len(x) <= 3 or not np.array_equal(np.arange(x[0], x[-1] + 1), x):\n            plot_func = sns.scatterplot\n        else:\n            plot_func = sns.lineplot\n\n        plot_func(x=x, y=y, ax=ax, marker=marker, label=label, color=color)\n\n    # combine data points for all series\n    xs_flat = list(flatten(xs))\n\n    # set x label of data point to the matching index\n    def format_fn(tick_val, tick_pos):\n        if int(tick_val) in xs_flat:\n            return index[int(tick_val)]\n        else:\n            return \"\"\n\n    # dynamically set x label ticks and spacing from index labels\n    ax.xaxis.set_major_formatter(FuncFormatter(format_fn))\n    ax.xaxis.set_major_locator(MaxNLocator(integer=True))\n\n    # Label the x and y axes\n    if x_label is not None:\n        ax.set_xlabel(x_label)\n\n    _y_label = y_label if y_label is not None else series[0].name\n    ax.set_ylabel(_y_label)\n\n    if legend:\n        ax.legend()\n    if _ax_kwarg_is_none:\n        return fig, ax\n    else:\n        return ax\n\n\ndef plot_correlations(\n    series,\n    lags=24,\n    alpha=0.05,\n    zero_lag=True,\n    acf_fft=False,\n    acf_adjusted=True,\n    pacf_method=\"ywadjusted\",\n    suptitle=None,\n    series_title=None,\n    acf_title=\"Autocorrelation\",\n    pacf_title=\"Partial Autocorrelation\",\n):\n    \"\"\"Plot series and its ACF and PACF values.\n\n    Parameters\n    ----------\n    series : pd.Series\n        A time series.\n\n    lags : int, default = 24\n        Number of lags to include in ACF and PACF plots\n\n    alpha : int, default = 0.05\n        Alpha value used to set confidence intervals. Alpha = 0.05 results in\n        95% confidence interval with standard deviation calculated via\n        Bartlett's formula.\n\n    zero_lag : bool, default = True\n        If True, start ACF and PACF plots at 0th lag\n\n    acf_fft : bool,  = False\n        Whether to compute ACF via FFT.\n\n    acf_adjusted : bool, default = True\n        If True, denonimator of ACF calculations uses n-k instead of n, where\n        n is number of observations and k is the lag.\n\n    pacf_method : str, default = 'ywadjusted'\n        Method to use in calculation of PACF.\n\n    suptitle : str, default = None\n        The text to use as the Figure's suptitle.\n\n    series_title : str, default = None\n        Used to set the title of the series plot if provided. Otherwise, series\n        plot has no title.\n\n    acf_title : str, default = 'Autocorrelation'\n        Used to set title of ACF plot.\n\n    pacf_title : str, default = 'Partial Autocorrelation'\n        Used to set title of PACF plot.\n\n    Returns\n    -------\n    fig : matplotlib.figure.Figure\n\n    axes : np.ndarray\n        Array of the figure's Axe objects\n    \"\"\"\n    _check_soft_dependencies(\"matplotlib\")\n    import matplotlib.pyplot as plt\n\n    series = check_y(series)\n    series = convert_to(series, \"pd.Series\", \"Series\")\n\n    # Setup figure for plotting\n    fig = plt.figure(constrained_layout=True, figsize=(12, 8))\n    gs = fig.add_gridspec(2, 2)\n    f_ax1 = fig.add_subplot(gs[0, :])\n    if series_title is not None:\n        f_ax1.set_title(series_title)\n    f_ax2 = fig.add_subplot(gs[1, 0])\n    f_ax3 = fig.add_subplot(gs[1, 1])\n\n    # Create expected plots on their respective Axes\n    plot_series(series, ax=f_ax1)\n    plot_acf(\n        series,\n        ax=f_ax2,\n        lags=lags,\n        zero=zero_lag,\n        alpha=alpha,\n        title=acf_title,\n        adjusted=acf_adjusted,\n        fft=acf_fft,\n    )\n    plot_pacf(\n        series,\n        ax=f_ax3,\n        lags=lags,\n        zero=zero_lag,\n        alpha=alpha,\n        title=pacf_title,\n        method=pacf_method,\n    )\n    if suptitle is not None:\n        fig.suptitle(suptitle, size=\"xx-large\")\n\n    return fig, np.array(fig.get_axes())\n", "path": "sktime/utils/plotting.py"}], "after_files": [{"content": "#!/usr/bin/env python3 -u\n# -*- coding: utf-8 -*-\n# copyright: sktime developers, BSD-3-Clause License (see LICENSE file)\n\"\"\"Common timeseries plotting functionality.\"\"\"\n\n__all__ = [\"plot_series\", \"plot_correlations\"]\n__author__ = [\"mloning\", \"RNKuhns\", \"Drishti Bhasin\"]\n\nimport math\n\nimport numpy as np\nimport pandas as pd\n\nfrom sktime.utils.validation._dependencies import _check_soft_dependencies\nfrom sktime.utils.validation.forecasting import check_y\nfrom sktime.utils.validation.series import check_consistent_index_type\n\nfrom statsmodels.graphics.tsaplots import plot_acf, plot_pacf\n\nfrom sktime.datatypes import convert_to\n\n\ndef plot_series(\n    *series, labels=None, markers=None, x_label=None, y_label=None, ax=None\n):\n    \"\"\"Plot one or more time series.\n\n    Parameters\n    ----------\n    series : pd.Series or iterable of pd.Series\n        One or more time series\n    labels : list, default = None\n        Names of series, will be displayed in figure legend\n    markers: list, default = None\n        Markers of data points, if None the marker \"o\" is used by default.\n        The length of the list has to match with the number of series.\n\n    Returns\n    -------\n    fig : plt.Figure\n    ax : plt.Axis\n    \"\"\"\n    _check_soft_dependencies(\"matplotlib\", \"seaborn\")\n    import matplotlib.pyplot as plt\n    from matplotlib.ticker import FuncFormatter, MaxNLocator\n    from matplotlib.cbook import flatten\n    import seaborn as sns\n\n    for y in series:\n        check_y(y)\n\n    series = list(series)\n    series = [convert_to(y, \"pd.Series\", \"Series\") for y in series]\n\n    n_series = len(series)\n    _ax_kwarg_is_none = True if ax is None else False\n    # labels\n    if labels is not None:\n        if n_series != len(labels):\n            raise ValueError(\n                \"\"\"There must be one label for each time series,\n                but found inconsistent numbers of series and\n                labels.\"\"\"\n            )\n        legend = True\n    else:\n        labels = [\"\" for _ in range(n_series)]\n        legend = False\n\n    # markers\n    if markers is not None:\n        if n_series != len(markers):\n            raise ValueError(\n                \"\"\"There must be one marker for each time series,\n                but found inconsistent numbers of series and\n                markers.\"\"\"\n            )\n    else:\n        markers = [\"o\" for _ in range(n_series)]\n\n    # create combined index\n    index = series[0].index\n    for y in series[1:]:\n        # check index types\n        check_consistent_index_type(index, y.index)\n        index = index.union(y.index)\n\n    # generate integer x-values\n    xs = [np.argwhere(index.isin(y.index)).ravel() for y in series]\n\n    # create figure if no Axe provided for plotting\n    if _ax_kwarg_is_none:\n        fig, ax = plt.subplots(1, figsize=plt.figaspect(0.25))\n\n    colors = sns.color_palette(\"colorblind\", n_colors=n_series)\n\n    # plot series\n    for x, y, color, label, marker in zip(xs, series, colors, labels, markers):\n\n        # scatter if little data is available or index is not complete\n        if len(x) <= 3 or not np.array_equal(np.arange(x[0], x[-1] + 1), x):\n            plot_func = sns.scatterplot\n        else:\n            plot_func = sns.lineplot\n\n        plot_func(x=x, y=y, ax=ax, marker=marker, label=label, color=color)\n\n    # combine data points for all series\n    xs_flat = list(flatten(xs))\n\n    # set x label of data point to the matching index\n    def format_fn(tick_val, tick_pos):\n        if int(tick_val) in xs_flat:\n            return index[int(tick_val)]\n        else:\n            return \"\"\n\n    # dynamically set x label ticks and spacing from index labels\n    ax.xaxis.set_major_formatter(FuncFormatter(format_fn))\n    ax.xaxis.set_major_locator(MaxNLocator(integer=True))\n\n    # Label the x and y axes\n    if x_label is not None:\n        ax.set_xlabel(x_label)\n\n    _y_label = y_label if y_label is not None else series[0].name\n    ax.set_ylabel(_y_label)\n\n    if legend:\n        ax.legend()\n    if _ax_kwarg_is_none:\n        return fig, ax\n    else:\n        return ax\n\n\ndef plot_lags(series, lags=1, suptitle=None):\n    \"\"\"Plot one or more lagged versions of a time series.\n\n    Parameters\n    ----------\n    series : pd.Series\n        Time series for plotting lags.\n    lags : int or array-like, default=1\n        The lag or lags to plot.\n\n        - int plots the specified lag\n        - array-like  plots specified lags in the array/list\n\n    suptitle : str, default=None\n        The text to use as the Figure's suptitle. If None, then the title\n        will be \"Plot of series against lags {lags}\"\n\n    Returns\n    -------\n    fig : matplotlib.figure.Figure\n\n    axes : np.ndarray\n        Array of the figure's Axe objects\n\n    Examples\n    --------\n    >>> from sktime.datasets import load_airline\n    >>> y = load_airline()\n    >>> fig, ax = plot_lags(y, lags=2) # plot of y(t) with y(t-2)\n    >>> fig, ax = plot_lags(y, lags=[1,2,3]) # plots of y(t) with y(t-1),y(t-2)..\n    \"\"\"\n    _check_soft_dependencies(\"matplotlib\")\n    import matplotlib.pyplot as plt\n\n    check_y(series)\n\n    if isinstance(lags, int):\n        single_lag = True\n        lags = [lags]\n    elif isinstance(lags, (tuple, list, np.ndarray)):\n        single_lag = False\n    else:\n        raise ValueError(\"`lags should be an integer, tuple, list, or np.ndarray.\")\n\n    length = len(lags)\n    n_cols = min(3, length)\n    n_rows = math.ceil(length / n_cols)\n    fig, ax = plt.subplots(\n        nrows=n_rows,\n        ncols=n_cols,\n        figsize=(8, 6 * n_rows),\n        sharex=True,\n        sharey=True,\n    )\n    if single_lag:\n        axes = ax\n        pd.plotting.lag_plot(series, lag=lags[0], ax=axes)\n    else:\n        axes = ax.ravel()\n        for i, val in enumerate(lags):\n            pd.plotting.lag_plot(series, lag=val, ax=axes[i])\n\n    if suptitle is None:\n        fig.suptitle(\n            f\"Plot of series against lags {', '.join([str(lag) for lag in lags])}\",\n            size=\"xx-large\",\n        )\n    else:\n        fig.suptitle(suptitle, size=\"xx-large\")\n\n    return fig, np.array(fig.get_axes())\n\n\ndef plot_correlations(\n    series,\n    lags=24,\n    alpha=0.05,\n    zero_lag=True,\n    acf_fft=False,\n    acf_adjusted=True,\n    pacf_method=\"ywadjusted\",\n    suptitle=None,\n    series_title=None,\n    acf_title=\"Autocorrelation\",\n    pacf_title=\"Partial Autocorrelation\",\n):\n    \"\"\"Plot series and its ACF and PACF values.\n\n    Parameters\n    ----------\n    series : pd.Series\n        A time series.\n\n    lags : int, default = 24\n        Number of lags to include in ACF and PACF plots\n\n    alpha : int, default = 0.05\n        Alpha value used to set confidence intervals. Alpha = 0.05 results in\n        95% confidence interval with standard deviation calculated via\n        Bartlett's formula.\n\n    zero_lag : bool, default = True\n        If True, start ACF and PACF plots at 0th lag\n\n    acf_fft : bool,  = False\n        Whether to compute ACF via FFT.\n\n    acf_adjusted : bool, default = True\n        If True, denonimator of ACF calculations uses n-k instead of n, where\n        n is number of observations and k is the lag.\n\n    pacf_method : str, default = 'ywadjusted'\n        Method to use in calculation of PACF.\n\n    suptitle : str, default = None\n        The text to use as the Figure's suptitle.\n\n    series_title : str, default = None\n        Used to set the title of the series plot if provided. Otherwise, series\n        plot has no title.\n\n    acf_title : str, default = 'Autocorrelation'\n        Used to set title of ACF plot.\n\n    pacf_title : str, default = 'Partial Autocorrelation'\n        Used to set title of PACF plot.\n\n    Returns\n    -------\n    fig : matplotlib.figure.Figure\n\n    axes : np.ndarray\n        Array of the figure's Axe objects\n    \"\"\"\n    _check_soft_dependencies(\"matplotlib\")\n    import matplotlib.pyplot as plt\n\n    series = check_y(series)\n    series = convert_to(series, \"pd.Series\", \"Series\")\n\n    # Setup figure for plotting\n    fig = plt.figure(constrained_layout=True, figsize=(12, 8))\n    gs = fig.add_gridspec(2, 2)\n    f_ax1 = fig.add_subplot(gs[0, :])\n    if series_title is not None:\n        f_ax1.set_title(series_title)\n    f_ax2 = fig.add_subplot(gs[1, 0])\n    f_ax3 = fig.add_subplot(gs[1, 1])\n\n    # Create expected plots on their respective Axes\n    plot_series(series, ax=f_ax1)\n    plot_acf(\n        series,\n        ax=f_ax2,\n        lags=lags,\n        zero=zero_lag,\n        alpha=alpha,\n        title=acf_title,\n        adjusted=acf_adjusted,\n        fft=acf_fft,\n    )\n    plot_pacf(\n        series,\n        ax=f_ax3,\n        lags=lags,\n        zero=zero_lag,\n        alpha=alpha,\n        title=pacf_title,\n        method=pacf_method,\n    )\n    if suptitle is not None:\n        fig.suptitle(suptitle, size=\"xx-large\")\n\n    return fig, np.array(fig.get_axes())\n", "path": "sktime/utils/plotting.py"}]}