<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def chains(xs, labels=None, truths=None, truth_color=u"#4682b4", burn=None, alpha=0.5, fig=None):
 """ Create a plot showing the walker values for each parameter at every step. :param xs: The samples. This should be a 3D :class:`numpy.ndarray` of size (``n_walkers``, ``n_steps``, ``n_parameters``). :type xs: :class:`numpy.ndarray` :param labels: [optional] Labels for all the parameters. :type labels: iterable of strings or None :param truths: [optional] Reference values to indicate on the plots. :type truths: iterable of floats or None :param truth_color: [optional] A ``matplotlib`` style color for the ``truths`` markers. :param burn: [optional] Reference step to indicate on the plots. :type burn: integer or None :param alpha: [optional] Transparency of individual walker lines between zero and one. :type alpha: float :param fig: [optional] Overplot onto the provided figure object. :type fig: :class:`matplotlib.Figure` or None :raises ValueError: If a ``fig`` is provided with the incorrect number of axes. :returns: The chain figure. :rtype: :class:`matplotlib.Figure` """


    n_walkers, n_steps, K = xs.shape

    if labels is not None:
        assert len(labels) == K

    if truths is not None:
        assert len(truths) == K

    factor = 2.0
    lbdim = 0.5 * factor
    trdim = 0.2 * factor
    whspace = 0.10
    width = 15.
    height = factor*K + factor * (K - 1.) * whspace
    dimy = lbdim + height + trdim
    dimx = lbdim + width + trdim

    if fig is None:
        fig, axes = plt.subplots(K, 1, figsize=(dimx, dimy))

    else:
        try:
            axes = np.array(fig.axes).reshape((1, K))
        except:
            raise ValueError("Provided figure has {0} axes, but data has "
                "parameters K={1}".format(len(fig.axes), K))

    lm = lbdim / dimx
    bm = lbdim / dimy
    trm = (lbdim + height) / dimy
    fig.subplots_adjust(left=lm, bottom=bm, right=trm, top=trm,
        wspace=whspace, hspace=whspace)
    if K == 1:
        axes = [axes]

    for k, ax in enumerate(axes):

        for walker in range(n_walkers):
            ax.plot(xs[walker, :, k], color="k", alpha=alpha)

        if burn is not None:
            ax.axvline(burn, color="k", linestyle=":")

        if truths is not None:
            ax.axhline(truths[k], color=truth_color, lw=2)

        ax.set_xlim(0, n_steps)
        if k < K - 1:
            ax.set_xticklabels([])
        else:
            ax.set_xlabel("Step")

        ax.yaxis.set_major_locator(MaxNLocator(4))
        [l.set_rotation(45) for l in ax.get_yticklabels()]
        if labels is not None:
            ax.set_ylabel(labels[k])
            ax.yaxis.set_label_coords(-0.05, 0.5)

    return fig