the newest edit
thicknessFunction
is not compatibile with ColorFunction
. It is because Mathematica is creating GraphicsComplex
for plots with ColotFunction
.
I have created procedure which is dealing with it. It is more useful than thicknessFunction[f_, f2_]
from the bottom of this post because MMA is taking care for scalling etc.
thick$color[f_] := ReplaceAll[#,
GraphicsComplex[x_List, y_List, z : OptionsPattern[__]] :>
GraphicsComplex[
x,
(y /.Line[x2_List,z2 : OptionsPattern[]] :> (Sequence @@ (
{Thickness[f @@ (Mean /@Transpose[x[[#]]])],
Line[#, VertexColors -> Automatic]} & /@ Partition[x2, 2, 1]))),
z]] &;
ParametricPlot[{Sin[t]+2 Sin[2 t], Cos[t]-2Cos[2t]}, {t, 0,3 Pi}, PlotPoints -> 500,
MaxRecursion -> 1, Axes -> False, ColorFunction -> "Rainbow"
] // thick$color[.01 (Abs[#1 #2]) &]
ParametricPlot[{Sin[t]+Sin[15t], Cos[t]-Cos[15t]}, {t, 0, 3 Pi},PlotPoints -> 2000,
MaxRecursion -> 1, Axes -> False, ColorFunction -> "DarkRainbow"
] // thick$color[.01 (Norm[{##}]) &]
Before last edit
With Your request:
[...] twice as thick at the minima and the maxima as it is at the roots. [...]
Artes's approach seems to be natural, because You can implement thickness dependance of function absolute value
, function's derivative
, or even argument value
just by including those into first list in Plot
.
However, it could be challenging if one does not feel good in analysis.
I think it is a good moment to try to create something like ColorFunction
for plot thickness. It is my solution:
thicknessFunction[f_] := ReplaceAll[#, Line[x__] :> (
{AbsoluteThickness[f @@ (Mean /@ Transpose[#])], Line@#} & /@ Partition[x, 2, 1])] &
OP's function case
In Your case such function should have form f = Function[{x,y}, 7 + 7 Abs[x]]
. Then thickness for y = 0
is 7
and twice as much, 14
, for y = 1
. So simple because Sin
is quite predictable :).
Following example is for 3 times thicker at extremes (just for clarity).
f = Function[{x, y}, 5 + 10 Abs[y]]
Plot[Sin[x], {x, 0, 3 Pi}, PlotPoints->500, MaxRecursion->1] // thicknessFunction[f]
Explanation
Note that many PlotPoints
and MaxRecursion->1
is a must for smooth result. thicknessFunction
is working on sample points and if we want smooth plot we need many but quite uniformly sampled points. Take a look:
(Plot[5 Sin[x], {x, 0, 10 Pi}, ImageSize -> 300, PlotPoints -> #1,
MaxRecursion -> #2] /. Line -> Point) & @@@ {{100, Automatic}, {100, 1}, {500, 1}}
Then we have to just replace those points to lines with thickness specified by us.
Examples
y = x with thickness proportional to x^2
and x
plot = Plot[x, {x, 0, 30}, AspectRatio -> 1, PlotPoints -> 500, MaxRecursion -> 1,
ImageSize -> 300];
plot // thicknessFunction[.4 #1^2 &]
plot // thicknessFunction[2 #1 &]
OP's case variations. Even including some analysis.
plot = Plot[Sin[2 x], {x, 0, 3 Pi}, PlotPoints -> 500, MaxRecursion -> 1,
PlotRange -> {{-2, 12}, {-1.5, 1.5}}, Frame -> True, Axes -> False];
plot // thicknessFunction[Abs[10 Sin'[2 #1]] + 2 #1 &]
plot // thicknessFunction[10 (#2 + 1) &]
Limitations
I have not tested it with all graphics functions in Mathmematica :) so I have to assume it is not bulletproof.
Important remark - it will not cooperate with ColorFunction
but:
color plot
Stealing halirutan's example lets implement colors:
thicknessFunction[f_, f2_] := ReplaceAll[#, Line[x__] :> (
{Blend["Rainbow", f2 @@ (Mean /@ Transpose[#])],
Thickness[f @@ (Mean /@ Transpose[#])],
Line@#} & /@ Partition[x, 2, 1])] &
ParametricPlot[{Sin[t] + 2 Sin[2 t], Cos[t] - 2 Cos[2 t]}, {t, 0, 3 Pi},
PlotPoints -> 2000, MaxRecursion -> 4, Axes -> False, ImageSize -> 500
] // thicknessFunction[.01 (Abs[#1 #2]) &, Abs[#2/2] &]
This have to be optimized and I must work on scalling etc. But do not have time now :(