We show that there is of family of inequalities associated to each compatibility structure of a set of events (a graph), such that the bound for noncontextual theories is given by the independence number of the graph, and the maximum quantum violation is given by the Lovasz tetha-function of the graph, which was originally proposed as an upper bound on its Shannon capacity. Probabilistic theories beyond quantum mechanics may have an even larger violation, which is given by the fractional packing number. We discuss the sets of probability distributions attainable by noncontextual, quantum, and generalized models; the latter two are shown to have semidefinite and linear characterizations, respectively. The implications for Bell inequalities are discussed. In particular, we show that every Bell inequality can be recast as a noncontextual inequality within this family. For details and proofs see arXiv:1010.2163 [quant-ph] or Phys. Rev. Lett. (short version).