I have a complicated tree I'd like to zoom in and investigate. It's quite dense and large.

Here's a simple way to reproduce the problem (my graph has 30K elements) but the 1K elements of this graph do a reasonable job as well.

g = Module[{weights, n = 1000},
  weights = Table[RandomReal[{0, Abs[i - j]^0.25 // N}], {i, n}, {j, n}];
   WeightedAdjacencyGraph[Table[ToString[i], {i, n}], 
    weights + Transpose[weights]]]

When I run the above, I get a graph that looks like: enter image description here

I'm interested in being able to zoom in/out easily (mouse wheel zooms in/out centered on the position of the mouse for instance).

Bonus points, if the zooming handles labels well. By default:

Graph[g, VertexLabels->"Name", EdgeLabels->"EdgeWeight"]

looks pretty atrocious.

  • $\begingroup$ You can try the 3D zoom/pan/rotate tools with GraphPlot3D[g]. Not sure it qualifies as being done "easily," though. $\endgroup$
    – Michael E2
    Commented Mar 20, 2023 at 0:31
  • 2
    $\begingroup$ DynamicImage[Show@g]? $\endgroup$
    – kglr
    Commented Mar 20, 2023 at 0:32
  • 1
    $\begingroup$ Maybe this, if the rasterization of DynamicImage isn't acceptable: gp = GraphPlot[g, VertexLabels -> "Name", EdgeLabels -> "EdgeWeight"]; viewRange = {{0.68, 0.72}, {0.63, 0.67}}; Show[gp, PlotRangePadding -> None, PlotRange -> MapThread[Rescale, {viewRange, {{0., 1.}, {0., 1.}}, PlotRange@gp}]]. You'd have to add the mouse interaction. DynamicImage is easier, though. $\endgroup$
    – Michael E2
    Commented Mar 20, 2023 at 0:47
  • $\begingroup$ @MichaelE2, GraphPlot3D is it. Zooming can be done (on Windoze) with <CTRL> panning with <SHIFT> and mousing. Make that an answer and I'll accept it. $\endgroup$
    – John
    Commented Mar 20, 2023 at 1:46
  • $\begingroup$ @MichaelE2 I suppose the next obvious question (to me) is, "why isn't this just part of 2D rendering? Or, is 3D rendering just how you're supposed to interact with graphics in general? DynamicImage sucks for this application. $\endgroup$
    – John
    Commented Mar 20, 2023 at 1:47


Your Answer

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

Browse other questions tagged or ask your own question.