Message Boards Message Boards

1
|
4881 Views
|
8 Replies
|
11 Total Likes
View groups...
Share
Share this post:

Use text as element of line for plotting?

Posted 7 years ago

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 of text as element of line for plotting.

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

ListPlot + ParametricPlot.

POSTED BY: Glenn Carlson
8 Replies

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

POSTED BY: Marco Thiel
Posted 7 years ago

fwiw, I decided to use Dashing[] to define a set of dashed lines distinguished by the number of dots between the dashes. For example... enter image description here

POSTED BY: Glenn Carlson

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...

POSTED BY: Sander Huisman
Posted 7 years ago

Thanks. That and a legend were two improvements I have in mind.

POSTED BY: Glenn Carlson

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.

POSTED BY: Sander Huisman
Posted 7 years ago

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}]

enter image description here

POSTED BY: Glenn Carlson

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]

enter image description here

Depending on the function you plot this might work easily or not. If not, one has to do some numerical approximations...

POSTED BY: Sander Huisman

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]
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract