gcrlsn
(Glenn Carlson)
March 27, 2017, 9:56am
1
I’m looking for a way to include text as an element of a line for plotting with Plot[]. Thanks!
The two examples below show what I’m aiming for.
Example 1: Add text manually.
Example 2: ListPlot, ParametricPlot, and Show:
p1 := ListPlot[Table[{Sin[n], Sin[2 n]}, {n, 50}],
PlotMarkers -> {Style["1", 12, Background -> White]}]
p2 := ParametricPlot[{Sin[n], Sin[2 n]}, {n, 0, 50}, PlotStyle -> Thin]
Show[p2, p1]
which generates
sghuisman
(Sander Huisman)
March 27, 2017, 1:38pm
2
You could do it like this:
lbls=Table[Text["1",{Sin[n],Sin[2 n]},Background->White],{n,0.0,2Pi,Pi/8}];
ParametricPlot[{Sin[n],Sin[2 n]},{n,0,2Pi},Epilog->lbls]
gcrlsn
(Glenn Carlson)
March 27, 2017, 2:25pm
3
That’s looking pretty close to what I want.
Thanks.
lbls1 = Table[
Text["1", {n, Sin[n]}, Background -> White], {n, 0.1, 2 Pi,
Pi/8}]; lbls2 =
Table[Text["2", {n, Sin[2 n]}, Background -> White], {n, 0.1, 2 Pi,
Pi/8}];
Plot[{Sin[n], Sin[2 n]}, {n, 0, 2 Pi}, Epilog -> {lbls1, lbls2}]
sghuisman
(Sander Huisman)
March 27, 2017, 4:24pm
4
You can also place them based on the arc length of the curve with some extra work:
ClearAll[f]
f[n_] := Sin[2 n]
alen[t_] = ArcLength[f[n], {n, 0, t}]
lens = MovingAverage[Subdivide[0, alen[2.0 Pi], 20], 2];
sols = FindRoot[alen[t] == #, {t, Pi}] & /@ lens;
sols = t /. sols;
pos = {#, f[#]} & /@ sols;
labels = Text["1", #, Background -> White] & /@ pos;
p1 = Plot[f[n], {n, 0, 2 Pi}, Epilog -> labels, AspectRatio -> Automatic]
Depending on the function you plot this might work easily or not. If not, one has to do some numerical approximations…
gcrlsn
(Glenn Carlson)
March 27, 2017, 5:11pm
5
Thanks. That and a legend were two improvements I have in mind.
sghuisman
(Sander Huisman)
March 27, 2017, 5:14pm
6
Note that I do it in now in an exact manner, for a general function the arc length of a curve is very complicated, a numerical approach is better suited then. Using Interpolation and some points you can quite easily cook up a function… Good Luck.
gcrlsn
(Glenn Carlson)
April 28, 2017, 10:33pm
7
fwiw, I decided to use Dashing[] to define a set of dashed lines distinguished by the number of dots between the dashes. For example…
sghuisman
(Sander Huisman)
April 28, 2017, 10:52pm
8
Nice plot. Is this for hot film sensors by any chance? To make them more distinguishable, you can also make one line solid Dashing[{}} and one line as Dotted. It is always tricky to make lines distinguishable. However now that color printers are far more common and a lot of people view papers on screens (telephone, tablets, laptops), the ‘gray-scale’ requirement is less strict than before…
mthiel
(Marco Thiel)
April 28, 2017, 11:46pm
9
Hi,
this is not a nice solution, but a slightly different approach.
Show[ParametricPlot[{Sin[n], Sin[2 n]}, {n, 0, 50}, PlotStyle -> Thin,Mesh -> #, MeshStyle -> Directive[Red]] & /@ {None, {10}} /. Point[x : {__Integer}] :> Map[Inset[Style["5", 20], #] &, x]]
and
Show[Plot[f[n], {n, 0, 2 Pi}, AspectRatio -> Automatic, Mesh -> #, MeshStyle -> Directive[Red]] & /@ {None, {10}} /. Point[x : {__Integer}] :> Map[Inset[Style["5", 20], #] &, x]]
Cheers,
Marco