# Degree distribution command in Mathematica

Just a simple question. Let k(i) be the degree of node i in an undirected network. Is there a defined command like "DegreeCentrality" to plot the degree distribution (plotting P(k) versus k) of a graph like

g = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}]


or do I have to write the code?

• Like Histogram? Histogram[DegreeCentrality[g], {1}, "Probability"]? Commented Apr 26, 2017 at 11:55
• Thank you. I just wrote: data = VertexDegree[g] // Tally, data2 = Table[{data[[i, 1]], data[[i, 2]]/VertexCount[g]}, {i, data // Length}] // Sort, plot1 = ListPlot[data2] and plot2 = Histogram[DegreeCentrality[g], {1}, "Probability"] which is yours. And they overlap well. Mine was ListPlot and yours was Histogram. You showed me the short way. Thanks again. Commented Apr 26, 2017 at 12:08
• No worries. If you want to make your own plot using the same underlying data as Histogram you can look at HistogramList. Commented Apr 26, 2017 at 12:23

Histogram[VertexDegree[g], {1}, "Probability",

• @Haliki You could use a more precise bin specification (2nd argument of Histogram), such as {-1/2, Max@VertexDegree[g] + 1/2, 1}. It seems that there are differences between various versions in how they determine the bins in automatic mode. BTW you can consider x.y to be a major version. 10.3 and 10.4 may have differences as big as 10.4 and 11.0. Commented Apr 26, 2017 at 13:02