<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def plot_experiment(mat, title="Experiment", axes_swapped=False, measure="Statistic", show_stdev=False, key_loc="lower right", outfile=None, wait=True):
 """ Plots the results from an experiment. :param mat: the result matrix to plot :type mat: ResultMatrix :param title: the title for the experiment :type title: str :param axes_swapped: whether the axes whether swapped ("sets x cls" or "cls x sets") :type axes_swapped: bool :param measure: the measure that is being displayed :type measure: str :param show_stdev: whether to show the standard deviation as error bar :type show_stdev: bool :param key_loc: the location string for the key :type key_loc: str :param outfile: the output file, ignored if None :type outfile: str :param wait: whether to wait for the user to close the plot :type wait: bool """


    if not plot.matplotlib_available:
        logger.error("Matplotlib is not installed, plotting unavailable!")
        return

    if not isinstance(mat, ResultMatrix):
        logger.error("Need to supply a result matrix!")
        return

    fig, ax = plt.subplots()
    if axes_swapped:
        ax.set_xlabel(measure)
        ax.set_ylabel("Classifiers")
    else:
        ax.set_xlabel("Classifiers")
        ax.set_ylabel(measure)
    ax.set_title(title)
    fig.canvas.set_window_title(title)
    ax.grid(True)
    ticksx = []
    ticks = []
    inc = 1.0 / float(mat.columns)
    for i in range(mat.columns):
        ticksx.append((i + 0.5) * inc)
        ticks.append("[" + str(i+1) + "]")
    plt.xticks(ticksx, ticks)
    plt.xlim([0.0, 1.0])
    for r in range(mat.rows):
        x = []
        means = []
        stdevs = []
        for c in range(mat.columns):
            mean = mat.get_mean(c, r)
            stdev = mat.get_stdev(c, r)
            if not math.isnan(mean):
                x.append((c + 0.5) * inc)
                means.append(mean)
                if not math.isnan(stdev):
                    stdevs.append(stdev)
        plot_label = mat.get_row_name(r)
        if show_stdev:
            ax.errorbar(x, means, yerr=stdevs, fmt='-o', ls="-", label=plot_label)
        else:
            ax.plot(x, means, "o-", label=plot_label)
    plt.draw()
    plt.legend(loc=key_loc, shadow=True)
    if outfile is not None:
        plt.savefig(outfile)
    if wait:
        plt.show()