'Set the contingency to display.'

def display_contingency(self):

    cont = self.contingencies
    (var, cvar) = (self.var, self.cvar)
    if ((cont is None) or (not len(cont))):
        return
    self.plot.clear()
    self.plot_prob.clear()
    self._legend.clear()
    self.tooltip_items = []
    if self.show_prob:
        self.ploti.showAxis('right')
    else:
        self.ploti.hideAxis('right')
    bottomaxis = self.ploti.getAxis('bottom')
    bottomaxis.setLabel(var.name)
    bottomaxis.resizeEvent()
    cvar_values = cvar.values
    colors = [QColor(*col) for col in cvar.colors]
    if (var and var.is_continuous):
        bottomaxis.setTicks(None)
        (weights, cols, cvar_values, curves) = ([], [], [], [])
        for (i, dist) in enumerate(cont):
            (v, W) = dist
            if len(v):
                weights.append(numpy.sum(W))
                cols.append(colors[i])
                cvar_values.append(cvar.values[i])
                curves.append(ash_curve(dist, cont, m=OWDistributions.ASH_HIST, smoothing_factor=self.smoothing_factor))
        weights = numpy.array(weights)
        sumw = numpy.sum(weights)
        weights /= sumw
        colors = cols
        curves = [(X, (Y * w)) for ((X, Y), w) in zip(curves, weights)]
        curvesline = []
        for (X, Y) in curves:
            X = (X + ((X[1] - X[0]) / 2))
            X = X[:(-1)]
            X = numpy.array(X)
            Y = numpy.array(Y)
            curvesline.append((X, Y))
        for t in ['fill', 'line']:
            curve_data = list(zip(curvesline, colors, weights, cvar_values))
            for ((X, Y), color, w, cval) in reversed(curve_data):
                item = pg.PlotCurveItem()
                pen = QPen(QBrush(color), 3)
                pen.setCosmetic(True)
                color = QColor(color)
                color.setAlphaF(0.2)
                item.setData(X, (Y / (w if self.relative_freq else 1)), antialias=True, stepMode=False, fillLevel=(0 if (t == 'fill') else None), brush=QBrush(color), pen=pen)
                self.plot.addItem(item)
                if (t == 'line'):
                    item.tooltip = '{}\n{}={}'.format(('Normalized    density    ' if self.relative_freq else 'Density    '), cvar.name, cval)
                    self.tooltip_items.append((self.plot, item))
        if self.show_prob:
            all_X = numpy.array(numpy.unique(numpy.hstack([X for (X, _) in curvesline])))
            inter_X = numpy.array(numpy.linspace(all_X[0], all_X[(-1)], (len(all_X) * 2)))
            curvesinterp = [numpy.interp(inter_X, X, Y) for (X, Y) in curvesline]
            sumprob = numpy.sum(curvesinterp, axis=0)
            legal = (sumprob > (0.05 * numpy.max(sumprob)))
            i = (len(curvesinterp) + 1)
            show_all = (self.show_prob == i)
            for (Y, color, cval) in reversed(list(zip(curvesinterp, colors, cvar_values))):
                i -= 1
                if (show_all or (self.show_prob == i)):
                    item = pg.PlotCurveItem()
                    pen = QPen(QBrush(color), 3, style=Qt.DotLine)
                    pen.setCosmetic(True)
                    prob = (Y[legal] / sumprob[legal])
                    item.setData(inter_X[legal], prob, antialias=True, stepMode=False, fillLevel=None, brush=None, pen=pen)
                    self.plot_prob.addItem(item)
                    item.tooltip = ((('Probability    that    \n' + cvar.name) + '=') + cval)
                    self.tooltip_items.append((self.plot_prob, item))
    elif (var and var.is_discrete):
        bottomaxis.setTicks([list(enumerate(var.values))])
        cont = numpy.array(cont)
        maxh = 0
        maxrh = 0
        scvar = cont.sum(axis=1)
        scvar[(scvar == 0)] = 1
        for (i, (value, dist)) in enumerate(zip(var.values, cont.T)):
            maxh = max(maxh, max(dist))
            maxrh = max(maxrh, max((dist / scvar)))
        for (i, (value, dist)) in enumerate(zip(var.values, cont.T)):
            dsum = sum(dist)
            geom = QRectF((i - 0.333), 0, 0.666, (maxrh if self.relative_freq else maxh))
            if self.show_prob:
                prob = (dist / dsum)
                ci = (1.96 * numpy.sqrt(((prob * (1 - prob)) / dsum)))
            else:
                ci = None
            item = DistributionBarItem(geom, (((dist / scvar) / maxrh) if self.relative_freq else (dist / maxh)), colors)
            self.plot.addItem(item)
            tooltip = '\n'.join((('%s:    %.*f' % (n, (3 if self.relative_freq else 1), v)) for (n, v) in zip(cvar_values, ((dist / scvar) if self.relative_freq else dist))))
            item.tooltip = '{}    ({}={}):\n{}'.format(('Normalized    frequency    ' if self.relative_freq else 'Frequency    '), cvar.name, value, tooltip)
            self.tooltip_items.append((self.plot, item))
            if self.show_prob:
                item.tooltip += '\n\nProbabilities:'
                for (ic, a) in enumerate(dist):
                    if (((self.show_prob - 1) != ic) and ((self.show_prob - 1) != len(dist))):
                        continue
                    position = ((-0.333) + (((ic + 0.5) * 0.666) / len(dist)))
                    if (dsum < 1e-06):
                        continue
                    prob = (a / dsum)
                    if (not (1e-06 < prob < (1 - 1e-06))):
                        continue
                    ci = (1.96 * sqrt(((prob * (1 - prob)) / dsum)))
                    item.tooltip += ('\n%s:    %.3f    \xc2\xb1    %.3f' % (cvar_values[ic], prob, ci))
                    mark = pg.ScatterPlotItem()
                    errorbar = pg.ErrorBarItem()
                    pen = QPen(QBrush(QColor(0)), 1)
                    pen.setCosmetic(True)
                    errorbar.setData(x=[(i + position)], y=[prob], bottom=min(numpy.array([ci]), prob), top=min(numpy.array([ci]), (1 - prob)), beam=numpy.array([0.05]), brush=QColor(1), pen=pen)
                    mark.setData([(i + position)], [prob], antialias=True, symbol='o', fillLevel=None, pxMode=True, size=10, brush=QColor(colors[ic]), pen=pen)
                    self.plot_prob.addItem(errorbar)
                    self.plot_prob.addItem(mark)
    for (color, name) in zip(colors, cvar_values):
        self._legend.addItem(ScatterPlotItem(pen=color, brush=color, size=10, shape='s'), escape(name))
    self._legend.show()
