How do I show the transition probabilities in a graph of a Markov process?

How do I get Graph to display the transition probabilities for a Markov process as labels on the graph's edges? The information is clearly present in the graph, but only displays when I hover over the edges. Is there a way to get the information to display as edge labels (without going through complex machinations)?

For example,

mp = DiscreteMarkovProcess[{1, 0, 0}, ({
{0.6, 0.1, 0.3},
{0.2, 0.7, 0.1},
{0.3, 0.3, 0.4}
})];
Graph[mp]

gives with no labeling of edges, even though I can hover over any edge to see the associated transition probability (as a tooltip).

You can extract the probabilities from the properties of the edges and assign them as edge labels using

g = Graph[mp];
Scan[(PropertyValue[{g, #}, EdgeLabels] = PropertyValue[{g, #}, "Probability"]) &,
EdgeList[g]]

g You can find this (and other) properties using the PropertyList function:

PropertyList[{g, 1 \[DirectedEdge] 2}]

(* {"Probability", EdgeLabels, EdgeShapeFunction, EdgeStyle} *)

From here, I used PropertyValue to set the properties. I imagine there are a few other (and possibly better/simpler) ways to accomplish this.

• great answer - appreciate the conciseness and the extra tidbit at the end on PropertyList. – Paul_A Oct 14 '15 at 3:18

You can use MarkovProcessProperties[mp, "TransitionMatrix"] as edge labels directly in Graph:

mp = DiscreteMarkovProcess[{1, 0, 0}, {{.6, .1, .3}, {.2, .7, .1}, {.3, .3, .4}}];

Graph[mp, EdgeLabels -> {DirectedEdge[i_, j_] :>
MarkovProcessProperties[mp, "TransitionMatrix"][[i, j]]}] 