# How to continuously control line thickness in plotting functions?

Posted 11 years ago
9515 Views
|
8 Replies
|
27 Total Likes
|
 I know that I can control color and opacity of lines in plotting functions  like in the example below. I also would like the line to change its thickness smoothly as we move in the positive x-direction. Is it possible to do via options to Plot? If not, - what could be the easiest approaches? Plot[Sin[x^2], {x, -3, 3}, PlotStyle -> Thickness[.04], PlotPoints -> 50,   ColorFunction -> Function[{x, y}, Directive[ColorData["Rainbow"][x], Opacity[Sin[10 y + 15 x]]]]]
8 Replies
Sort By:
Posted 1 year ago
 Hi Ahmed. Of course there was the objective of the code. Thanks.
Posted 1 year ago
 Very interesting techniques to control the thickness of the curves. It well suited in animating the orbit of celestial objects. Thanks for this sharing. x[t_] = 50 Cos[t]; y[t_] = 50 Sin[t]; z[t_] = 0 t; H[t_, a_] = ParametricPlot3D[{x[t], y[t], z[t]}, {t, a, a - 1.8 Pi}, PlotRange -> {{-60, 60}, {-60, 60}, {-5, 5}}, PlotStyle -> {Red, Opacity[0.6], Tube[t/200]}]; S[t_] = Graphics3D[Sphere[{x[t], y[t], z[t]}, 2]]; Animate[Show [H[t, a], S[a]], {a, 0, 2 Pi}] 
Posted 1 year ago
 Hi Mohammed, Your code didn't work at first trial, but with little modifications, it worked, hope this is what you intended to show
Posted 11 years ago
 It crossed my mind that in some situations we can take advantage of Filling:Table[Plot[Evaluate[  Flatten[{#, # + amp (x + 3.5), # - amp (x + 3.5)} & /@ {Cos[x^2], .3 Sin[10 x]}]], {x, -3, 3},  PlotPoints -> 50, Filling -> {3 -> {2}, 5 -> {6}}, PlotStyle -> {None, Gray, Gray, None, Gray, Gray},  ColorFunction -> Function[{x, y}, Directive[ColorData["Rainbow"][x], Opacity[x]]],  AspectRatio -> 1/4, ImageSize -> 500], {amp, .005, .15, .05}]The controlled thickness is only vertical in this case. It will not work in some other cases, for example ParametricPlot does not have Filling option at all. But, in ParametricPlot case, for example, we can use the function itself, because it can show bounded areas:ParametricPlot[{(v + 1) u Cos[u], (v + 1) u Sin[u]}, {u, 0, 6 Pi}, {v, 0.5, 1}, Mesh -> None, MaxRecursion -> 4, Axes -> False, BoundaryStyle -> GrayLevel[.9],  ColorFunction -> Function[{x, y, u, v}, Directive[ColorData["Rainbow"][u v], Opacity[v]]]]
Posted 11 years ago
 Using MeshShading will also work but not as good as ParametricPlot and using Filling but it doesn't change the function to use and original input.Plot[Sin[x^2], {x, -3, 3}, Mesh -> {Range[-3, 3, 6/100]}, MeshStyle -> None,MeshShading -> (Directive[Hue[Rescale[#, {-3, 3}, {0, 1}]],AbsoluteThickness[Rescale[#, {-3, 3}, {1, 20}]]] & /@Range[-3, 3, 6/100]), PlotRangePadding -> Scaled[0.05]]
Posted 11 years ago
 Min, that is an awful abuse of Mesh.  I like it.
Posted 11 years ago
 This whole thread demonstrates mostly for better the stupifying generality of Mathematica. Awesome.
Posted 11 years ago
 Not a general solution, but this works some times:ParametricPlot3D[{{x, Sin[x^2], x}, {x, Cos[x^2], x}}, {x, 0 - 3, 3},PlotStyle -> {{Opacity[0.5], Tube[x/2000]}, {Opacity[0.3], Tube[x/2000]}},ViewPoint -> {0, 0, 1000}, PlotRange -> All, ColorFunction -> "Rainbow"]npts = 12;ParametricPlot3D[{{Cos[2 t], Sin[2 t], Cos}, {Sin[2 t], Cos[2 t], Sin}}, {t, 0, 2 Pi},  PlotStyle -> {{Red, Tube[{0.1 Sin[t/(2 Pi)], 0.1}, PlotPoints -> npts, Frame -> "Frenet"]},                {Yellow, Tube[{0.1 Sin[t/(2 Pi)], 0.1}, Frame -> "Frenet", PlotPoints -> npts]}},  PlotRange -> All, MaxRecursion -> 0, PlotPoints -> 200]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments