4
$\begingroup$

I would like to apply a ColorFunction across the width of the line so that the line remains bright white at the center and fades to background color shortly thereafter at the edges creating the look of an oscilloscope trace (or at least, that's what I think it will result in). (something similar to this)

Plot[x, {x, -1, 1}
 , PlotStyle -> {Thickness[0.04], White}
 , Background -> Darker@Cyan
 ]

enter image description here

From what I understand, the ColorFunction works along the length of the line as follows;

Plot[x, {x, -1, 1}
 , PlotStyle -> {Thickness[0.04], White}
 , Background -> Darker@Cyan
 , ColorFunction -> Hue
 ]

enter image description here

Thanks in advance for your replies and suggestions.

$\endgroup$
9
  • $\begingroup$ Something like ColorFunction -> (Opacity[#1, White] &) and removing the White from the PlotStyle? $\endgroup$
    – MarcoB
    Commented Jan 7, 2022 at 21:12
  • $\begingroup$ Plot[Sin[x], {x, -4, 4}, PlotStyle -> {Thickness[0.04]}, ColorFunction -> (Opacity[#1, White] &), Background -> Darker@Cyan] results in a gradient in the x-direction shown here. $\endgroup$
    – Syed
    Commented Jan 7, 2022 at 21:17
  • 1
    $\begingroup$ Like an oscilloscope trace, bright along the center of the trace and fading width wise as it goes across the screen. (something similar to this). $\endgroup$
    – Syed
    Commented Jan 7, 2022 at 21:24
  • 1
    $\begingroup$ For glowing lines you could have a look at this: mathematica.stackexchange.com/a/228763/72682 $\endgroup$
    – flinty
    Commented Jan 7, 2022 at 21:31
  • 1
    $\begingroup$ something like ParametricPlot[{x, 1 - t + x}, {x, -1, 1}, {t, -.1, .1}, BoundaryStyle -> None, Background -> Darker@Cyan, ColorFunction -> (Blend[{Darker@Cyan, White, Darker@Cyan}, (#4 + .1)/.2] &), ColorFunctionScaling -> False, AspectRatio -> 1/2]? $\endgroup$
    – kglr
    Commented Jan 7, 2022 at 21:39

4 Answers 4

6
$\begingroup$

It's possible to make textured lines like in this answer and you could use the linear gradient texture from my other answer on glowing graph edges. However, if you need curves, a lot of textured lines (actually polygons) will have gaps and it looks bad.

For something like a scope trace for curves, as mentioned in the comments, it might be better to go with a DensityPlot like this:

plot = Plot[Sin[8.3 x] + 0.5 Cos[4. x], {x, 0, 3}];
line = Cases[plot, Line[_], Infinity] // First;
reg = SignedRegionDistance[line];
DensityPlot[Quiet@Exp[-reg[{x, y}]^2/0.002], {x, 0, 3}, {y, -3, 3}, 
 PlotRange -> All, PlotPoints -> 50, ColorFunction -> "AvocadoColors"]

enter image description here

A better ColorFunction and some axes can make it look more scope-y

cols = {{0., Darker[Green, .8]}, {0.7, Darker[Green, .4]}, {0.85, Green}, {1, White}};
DensityPlot[Quiet@Exp[-reg[{x, y}]^2/0.004], {x, 0, 3}, {y, -3, 3}, 
 PlotRange -> All, PlotPoints -> 50, 
 ColorFunction -> (Blend[cols, #1] &), GridLines -> Automatic]

enter image description here

$\endgroup$
4
$\begingroup$

Using a slight modification of this answer:

ClearAll[pCurve]
pCurve[f_, width_: 1/2][x_, u_] := {x, f@x} + (1-2 u) width/2 Cross@Normalize[{1, f'@x}]

colorFunc[color_: Red] := Blend[{color, White, color}, #4] &;

Examples:

f1[x_] := x

f2 = # Sin@# &;

color = Darker@Cyan;

ParametricPlot[pCurve[f1][x, t], {x, -3, 3}, {t, 0, 1}, 
 BoundaryStyle -> color, Background -> color, 
 ColorFunction -> colorFunc[color], Frame -> False, Axes -> True]

enter image description here

ParametricPlot[pCurve[f2, 1][x, t], {x, -2 Pi, 2 Pi}, {t, 0, 1}, 
 BoundaryStyle -> color, Background -> color, 
 ColorFunction -> colorFunc[color], Frame -> False, Axes -> True]

enter image description here

$\endgroup$
2
$\begingroup$
Plot[x,
  {x, -1, 1},
  PlotStyle -> Thickness[0.04],
  Background -> Darker@Cyan,
  ColorFunction -> (Opacity[4 (#1 - #1^2), White] &)
]

enter image description here

$\endgroup$
0
$\begingroup$

Using Haloing[]: (introduced with v13.3)

Framed[#
,Background->GrayLevel[0.5]
,RoundingRadius->10
,FrameMargins->5
]&@Framed[#
,Background->GrayLevel[0.75]
,RoundingRadius->5
,FrameMargins->5
]&@
Plot[{Sin[8.3 x] + 0.5 Cos[4. x]}
, {x, 0, 3}
,Axes->False
, PlotStyle -> {White,Haloing[Lighter@Cyan,1,4]}
,Background->Blend[{Cyan,Gray}]
,Frame->True
,GridLines->Automatic
,GridLinesStyle->{{Black,Dotted},{Black,Dotted}}
,Method->{"GridLinesInFront"->True}
,ImageMargins->{{10,20},{10,20}}
]

enter image description here

$\endgroup$

Your Answer

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

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