I have seen many queries on zooming in on plots etc. But I haven't seen any regarding 2D graphs. For eg if I have a graph like

Graph[{1->2, 2->3, 3->1}].

It will create a graph. I have a similar graph which is very complex which has vertices very close by. I want to zoom in on a set of nodes and see how they are related. I can increase the image size or decrease the vertex size, but both of them are not helping since the graph is pretty huge and has a complex network of nodes which are clustered together and connected to each other. I can use NeighbourhoodGraph function. But is there any way to zoom in on the graph itself to see the how the nodes are connected to each other?


2 Answers 2


You can do this using Show and PlotRange which can be used in combination with graphs. To determine the full PlotRange of the original Graph you could use AbsoluteOptions to determine the values of the VertexCoordinates of the graph. The function CoordinateBoundingBox, introduced in V10.1, is helpful here:

g = RandomGraph[{70, 200}]

Mathematica graphics

{xrange, yrange} =  VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates] 
                      // CoordinateBoundingBox // Transpose
(* {{0., 5.33683}, {0., 4.09534}}  *)

An interactive example of zooming:

zoomGraph[g_Graph] :=
  pt = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates] // CoordinateBoundingBox;
         Graphics[{FaceForm[], EdgeForm[Red], Rectangle @@ pt}], 
         ImageSize -> 400
    Dynamic[Show[g, PlotRange -> Transpose[pt], ImageSize -> 400]]


enter image description here

In some cases, the zoomed-in vertices may become too big: you could reduce the vertex size as follows:

zoomGraph[Graph[g, VertexSize -> 0.5]]

or add a VertexSize to the zoomed-in graph.

  • $\begingroup$ How can I use this feature with Graphics[] instead? $\endgroup$
    – Stratus
    Jan 27, 2019 at 14:30

This is a prototype, it can not handle Text Inset and some more complicated directives efficiently but I don't have time / motivation to improvie it.

Here's something fun:

g = Normal @ Show @ CommunityGraphPlot[
     ExampleData[{"NetworkGraph", "DolphinSocialNetwork"}]

enter image description here

dist = Normalize[#] (2./Pi ArcTan[Norm[5 #]]) &;

 pts = Union@Cases[g, {_?NumericQ, _?NumericQ}, \[Infinity]];

 prims = (
    First[g] /. Thread[# -> Range@Length@#] &@pts)/. FilledCurve -> (# &);

          GraphicsComplex[ Dynamic[dist /@ pts], prims]
      ImageSize -> 500, 
      PlotRange -> 1], 
  {"MouseDown" :> {drag = {MousePosition@"GraphicsScaled"}}, 
   "MouseDragged" :> {drag = {Last@drag, 
        pts = (# + 5 (#2 - # & @@ drag) & /@ pts)}}]}]]

enter image description here

  • $\begingroup$ Fun indeed. What parameter do I change to modify the magnitude of the fish-eye effect? $\endgroup$
    – Mr.Wizard
    Jan 29, 2016 at 7:35
  • $\begingroup$ @Mr.Wizard The multiplier in dist inside Norm should be enough. $\endgroup$
    – Kuba
    Jan 29, 2016 at 8:48
  • $\begingroup$ @Kuba +1 looks awesome, I was wondering if it would be possible to make this solution more generically applicable? Say, how could I pass a Graph and receive output as above? $\endgroup$ Mar 28, 2016 at 8:38
  • $\begingroup$ @E.Doroskevic I was trying but labels are placed weirdly because "next to" after transformation may be "next to something else". There were also some other minor issues, I will try to back to that when I have more ideas and time. Thanks for feedback :) $\endgroup$
    – Kuba
    Mar 31, 2016 at 8:02
  • $\begingroup$ @Kuba I appreciate that, thank you! I think this is a brilliant way to visualize large network graphs. Hope you will find a way to develop this idea forward! $\endgroup$ Mar 31, 2016 at 8:10

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.