1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ does ListPlot[MapIndexed[Labeled[#,Style[ #2[[1]], FontSize->Scaled[.02]], Center] &, data], PlotStyle->PointSize[.004], PlotRange -> {{0, 1}, {0, 1}}] give what you need? $\endgroup$ – kglr Sep 16 '19 at 20:05
  • $\begingroup$ @kglr That doesn't put any text on the plot. $\endgroup$ – Jerry Guern Sep 16 '19 at 20:20
  • $\begingroup$ Jerry, it does in version 12 (wolfram cloud) $\endgroup$ – kglr Sep 16 '19 at 20:21
  • $\begingroup$ you can try Graphics[Table[{Text[Style[i, FontSize -> Scaled[.02]], data[[i]]]}, {i, 1, Length[data]}], Axes -> True]? $\endgroup$ – kglr Sep 16 '19 at 20:23
  • $\begingroup$ 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. $\endgroup$ – Vitaliy Kaurov Sep 16 '19 at 21:06
3
$\begingroup$
ClearAll[zoom]
zoom[Dynamic[coords_], edgestyle_: Blue, facestyle_: LightBlue] := 
 Graphics[{Directive[EdgeForm[{edgestyle, Dashed}], facestyle, 
    Opacity[.3]], Dynamic[Rectangle @@ coords], 
   MapThread[Locator[Dynamic[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]]]

enter image description here

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Jerry Guern Sep 16 '19 at 20:34
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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