def plot_confusion_matrix(cm, xlabel, ylabel, xnames, ynames,  title='Confusion matrix', cmap=pl.cm.Blues):
    pl.grid(False)
    pl.imshow(cm, interpolation = 'none',cmap=cmap)
    pl.title(title)
    pl.colorbar()
    tick_marksx = np.arange(len(xnames))
    tick_marksy = np.arange(len(ynames))
    pl.xticks(tick_marksx, xnames)
    pl.yticks(tick_marksy, ynames)
    pl.tight_layout()
    pl.ylabel(ylabel)
    pl.xlabel(xlabel)