# Can Mathematica produce zoomable plots, with embedded text of varying size?

I'm trying to figure out how do something on MMa that's fairly easy on Matlab. I some data points that each maps a numerical parameters to a point in 2D space. I need to plot the parameter values to the point in 2D. The code below gets that much done, even if a bit clumsily. The 'data' is simulated with random numbers.

data = RandomReal[1, {200, 2}];
b = Table[{Text[i, data[[i]]]}, {i, 1, Length[data]}];
ListPlot[{0, 0}, PlotStyle -> PointSize[.004], PlotRange -> {{0, 1}, {0, 1}}, Epilog -> b]


So first, is there anyway to plot JUST when I've put into that 'epilog' b, without having to fake that {0,0} data point. I can only get ListPlot to put test on a plot as an epilog, and it will only plot epilogs after some data.

Second, is there any way to create a plot that I can zoom in on, with the text fonts resizing to remain readable? If you run the code above, the plot is to cluttered to read, but if I could zoom in and it resized, it would be readable wherever I was looking.

• does ListPlot[MapIndexed[Labeled[#,Style[ #2[[1]], FontSize->Scaled[.02]], Center] &, data], PlotStyle->PointSize[.004], PlotRange -> {{0, 1}, {0, 1}}] give what you need?
– kglr
Sep 16, 2019 at 20:05
• @kglr That doesn't put any text on the plot. Sep 16, 2019 at 20:20
• Jerry, it does in version 12 (wolfram cloud)
– kglr
Sep 16, 2019 at 20:21
• you can try Graphics[Table[{Text[Style[i, FontSize -> Scaled[.02]], data[[i]]]}, {i, 1, Length[data]}], Axes -> True]?
– kglr
Sep 16, 2019 at 20:23
• An easy workaround. Click on the plot to see orange frame. Drag the corners. Regions will zoom-in and resolve better, but font will stay the same size and stop overlapping for large enough frame. Also note ListPlot[{}] takes empty lists - no data needed. Sep 16, 2019 at 21:06

ClearAll[zoom]
zoom[Dynamic[coords_], edgestyle_: Blue, facestyle_: LightBlue] :=
Graphics[{Directive[EdgeForm[{edgestyle, Dashed}], facestyle,
Opacity[.3]], Dynamic[Rectangle @@ coords],
Graphics[{#2, Rectangle[]}, ImageSize -> 8],
LocatorRegion -> Full] &, {{1, 2}, {Black, Gray}}]}]

SeedRandom[1]
data = RandomReal[1, {200, 2}];

c = MapIndexed[{Text[Style[#2[[1]], "Panel", FontSize -> Small], #]} &, data];

plt = Graphics[c, Frame -> True, ImageSize -> 300];

Deploy @ DynamicModule[{pta = Transpose[PlotRange[plt]]},
Row[{Show[plt, zoom[Dynamic[pta]]],
Show[plt, PlotRange -> Dynamic[Transpose[pta]],
AspectRatio -> Full, ImageSize -> {{300, 500}, 300}]},
Spacer[10]]]


• Yes, that does pretty much what my code does, minus the fake data point at {0,0}, so it addresses my first question. But when you resize with the mouse, the fonts get bigger too and end up overlapping just as badly. But is there any way in MMa to make a truly zoomable plt, where I can click on the clusters and get a close-up? Sep 16, 2019 at 20:34

One way to resize things is to use a Manipulate:

data = RandomReal[1, {200, 2}];
Manipulate[b = Table[{Text[i, data[[i]]]}, {i, 1, Length[data]}];
ListPlot[{0, 0}, PlotStyle -> PointSize[.004],
PlotRange -> {{0, 1}, {0, 1}}, Epilog -> b, ImageSize -> i], {i, 100, 2000}]


Now you can resize the plot using the slider... it zooms in as you might expect.