I have constructed a small tool to produce documentation for my code. It constructs dataflow diagrams (my own version) using an association-based data structure and Graph.

The DFDs look pretty good except that some of the labeling gets buried behind some of the vertices, and I haven't been able to figure out how to make them layer as I wish. Take a look at the vertex "buildPartnerGraphLF" which is on top of the edge label.

As background, the association data structure gets translated into the lists below which are then fed to Graph. I include the raw lists. Any help would be appreciated.

 vL = {Property["buildLimitedPGraphLF", VertexShapeFunction -> "Circle"], 
  Property["buildPartnerGraphLF", {VertexShapeFunction -> "Circle", 
   VertexStyle -> RGBColor[0.87, 0.94, 1], VertexSize -> {0.3, 0.3}}],
  Property["dealDataDS", VertexShapeFunction -> "Square"], 
  Property["fullPartL", VertexShapeFunction -> "RoundedRectangle"], 
  Property["leadsAndCoLeadsDS", VertexShapeFunction -> "Square"], 
  Property["seedPartnerL", VertexShapeFunction -> "RoundedRectangle"], 
  Property["shortSeedPL", VertexShapeFunction -> "RoundedRectangle"]}

eL = {"buildLimitedPGraphLF" \[DirectedEdge] "buildPartnerGraphLF", 
 "buildLimitedPGraphLF" \[DirectedEdge] "fullPartL", 
 "buildPartnerGraphLF" \[DirectedEdge] "getPartnerF", 
 "buildPartnerGraphLF" \[DirectedEdge] "leadsAndCoLeadsDS", 
 "buildPartnerGraphLF" \[DirectedEdge] "seedPartnerL", 
 "dealDataDS" \[DirectedEdge] "getPartnerF", 
 "frequentPartF" \[DirectedEdge] "shortSeedPL", 
 "getPartnerF" \[DirectedEdge] "buildPartnerGraphLF", 
 "getPartnerF" \[DirectedEdge] "dealDataDS", 
 "leadsAndCoLeadsDS" \[DirectedEdge] "buildPartnerGraphLF", 
 "medF" \[DirectedEdge] "frequentPartF", 
 "medF" \[DirectedEdge] "getPartTimesF", 
 "seedPartnerL" \[DirectedEdge] "frequentPartF", 
 "shortSeedPL" \[DirectedEdge] "buildLimitedPGraphLF"}

eLabL={"buildLimitedPGraphLF" \[DirectedEdge] "buildPartnerGraphLF" -> 
  "brokerS medI", 
 "buildLimitedPGraphLF" \[DirectedEdge] "fullPartL" -> 
 "buildPartnerGraphLF" \[DirectedEdge] "getPartnerF" -> 
 "buildPartnerGraphLF" \[DirectedEdge] "leadsAndCoLeadsDS" -> 
  "brokerS", "dealDataDS" \[DirectedEdge] "getPartnerF" -> "partnerL",
  "getPartnerF" \[DirectedEdge] "buildPartnerGraphLF" -> "partnerL", 
 "getPartnerF" \[DirectedEdge] "dealDataDS" -> "dealS", 
 "leadsAndCoLeadsDS" \[DirectedEdge] "buildPartnerGraphLF" -> 
  "leadOrCoL", "medF" \[DirectedEdge] "frequentPartF" -> "medI", 
 "medF" \[DirectedEdge] "getPartTimesF" -> "brokerS", 
 "shortSeedPL" \[DirectedEdge] "buildLimitedPGraphLF" -> 

g1 = Graph[vL, eL, EdgeLabels -> eLabL, 
  VertexLabels -> Placed["Name", Center], VertexSize -> {0.25, .25}, 
  ImageSize -> Full]

enter image description here

  • $\begingroup$ Use as option a color with opacity VertexStyle -> RGBColor[0.77, 0.76, 0.21, .3] would be a quick way to see all labeling. $\endgroup$ Commented Dec 22, 2016 at 21:11

2 Answers 2


You can move all of the text to the top with

Show[Show@g1 /. {{_Text -> {}}, {_Disk | _Rectangle | _Arrow | _FilledCurve -> {}}}]

Mathematica graphics

This uses Show to convert the graph to a normal graphics object, and then uses Show again to layer a copy with only the text over a copy with all of the text removed.

  • $\begingroup$ I had to read that replacement three times to see what you are doing. That's clever! $\endgroup$
    – Mr.Wizard
    Commented Dec 23, 2016 at 2:34
  • 2
    $\begingroup$ @Mr.Wizard Thanks! I think that's the first time I've made good use of the "list-of-lists" syntax for ReplaceAll. $\endgroup$ Commented Dec 23, 2016 at 3:14
  • $\begingroup$ Awesome is the word that suggests itself to me! $\endgroup$ Commented Dec 23, 2016 at 17:23
  • $\begingroup$ For those reading this, @Simon Rochester has (in one line) converted the graph to a graphic, then created two versions of the graphic, using replacement rules to turn "off" all of the text in the first and all of the other graphics in the second. Then Show essentially overlays the text-y one on top of the graphic-y one. Thanks! $\endgroup$ Commented Dec 23, 2016 at 17:53
  • $\begingroup$ @mdc18550 You're welcome. I just found a way to shorten it some more -- you can use Show instead of FullGraphics to convert the graph object to graphics; that removes the need to specify ImageSize again. $\endgroup$ Commented Dec 23, 2016 at 23:42

An approach to get a Graph object as the final output:

  1. Make the labels in g1 invisible.
  2. Extract the Insets and InsetBoxes that contain the vertex and edge labels.
  3. Use the extracted labels as Epilog using SetProperty.


g2 = SetProperty[g1, Thread[{EdgeLabelStyle, VertexLabelStyle} -> Opacity[0]]];
labels = Cases[Show@g1 , i : (Inset | InsetBox)[__] :> i, {0,  ∞}];
g3 = SetProperty[g2, Epilog -> labels]

enter image description here

Head @ g3


Alternatively, do all in a single step:

SetProperty[SetProperty[g1, Thread[{EdgeLabelStyle, VertexLabelStyle} -> Opacity[0]]], 
 Epilog -> Cases[Show@g1 , i : (Inset | InsetBox)[__] :> i, {0, ∞}]]

same picture


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.