"""Utilities to work with plots."""

import matplotlib.pyplot as plt


# Colors for Plots
COLORS = [(31, 119, 180),  (174, 199, 232), (255, 127, 14),  (255, 187, 120),
          (44, 160, 44),   (152, 223, 138), (214, 39, 40),   (255, 152, 150),
          (148, 103, 189), (197, 176, 213), (140, 86, 75),   (196, 156, 148),
          (227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),
          (188, 189, 34),  (219, 219, 141), (23, 190, 207),  (158, 218, 229)]

for i in range(len(COLORS)):
    r, g, b = COLORS[i]
    COLORS[i] = (r / 255., g / 255., b / 255.)


def subplots(nrows=1, ncols=1, figsize=None, xlabel=None, ylabel=None):
    plt.rc("font", size=20)
    pre, axs = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize)

    all_axs = [axs] if nrows * ncols == 1 else axs
    for ax in all_axs:
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
        ax.grid(axis="y", linewidth=.2)
        ax.spines["top"].set_visible(False)
        ax.spines["bottom"].set_visible(False)
        ax.spines["right"].set_visible(False)
        ax.spines["left"].set_visible(False)
        ax.color_nr = 0

    return pre, axs


def plot(ax, x, y, label=None, color=None):
    if color is None:
        color = COLORS[ax.color_nr]
        ax.color_nr += 1
    elif isinstance(color, int):
        color = COLORS[color]

    ax.plot(x, y, color=color, label=label)

@@ -644,24 +644,362 @@
 abel=None):%0A
+    %22%22%22%0A    Creates subplots from matplotlib.%0A%0A    Args:%0A        nrows (int):%0A        ncols (int):%0A        figsize (tuple%5Bint, int%5D):%0A        xlabel (str):%0A        ylabel (str):%0A%0A    Returns:%0A        fig (matplotlib.figure.Figure): the matplotlib figure%0A        ax (matplotlib.Axes or list%5Bmatplotlib.Axes%5D): axes for the subplot%0A    %22%22%22%0A
     plt.rc(%22
@@ -1541,191 +1541,1118 @@
     
-if color is None:%0A        color = COLORS%5Bax.color_nr%5D%0A        ax.color_nr += 1%0A    elif isinstance(color, int):%0A        color = COLORS%5Bcolor%5D%0A%0A    ax.plot(x, y, color=color, label=label)
+%22%22%22%0A    Plots the given %60x%60 and %60y%60 into %60ax%60. Optionally adds a label and a color.%0A%0A    Args:%0A        ax (matplotlib.Axis): matplotlib's axis%0A        x (list%5Bfloat%5D): list of values for the %60x%60 axis%0A        y (list%5Bfloat%5D): list of values for the %60y%60 axis%0A        label (str): name for the line plot%0A        color (int or None): number for a color, or None to chose automatically%0A    %22%22%22%0A    if color is None:%0A        color = COLORS%5Bax.color_nr%5D%0A        ax.color_nr += 1%0A    elif isinstance(color, int):%0A        color = COLORS%5Bcolor%5D%0A%0A    ax.plot(x, y, color=color, label=label)%0A%0A%0Adef moving_average(ys, window=5):%0A    %22%22%22%0A    Calculates moving average window of the given list of values.%0A%0A    Args:%0A        ys (list%5Bfloat%5D): list of values%0A        window (int): size of the window%0A%0A    Returns:%0A        values (list%5Bfloat%5D): list of values as moving average from %60ys%60. Same%0A          size as %60ys%60.%0A    %22%22%22%0A    values = %5B%5D%0A    result = %5B%5D%0A    for y in ys:%0A        values.append(y)%0A        if len(values) %3E window:%0A            values = values%5B1:%5D%0A        result.append(sum(values) / len(values))%0A    return result
 %0A

add function to calculate moving average