3
$\begingroup$

I have a 3D plot of dozens of random curves which have different colors by default. I want to keep the default colors but then I need all the curves to get a Thick style. If I use the option PlotStyle -> Thick, then all curves are turned to black. I know this should be very basic, but I don't get it!

Here's a MWE to show the issue:

vec[t_, x_, y_, z_] := {x t, y t, z t}

x0[n_] := RandomReal[{-10, 10}]
y0[n_] := RandomReal[{-10, 10}]
z0[n_] := RandomReal[{-10, 10}]

vectors[t_] := Table[vec[t, x0[n], y0[n], z0[n]], {n, 1, 10}]

randVectors = ParametricPlot3D[Evaluate@vectors[t], {t, -30, 30}, PlotStyle -> {Thick}];

Show[
 randVectors,
 PlotRange -> Automatic,
 Axes -> None,
 BoxStyle -> Thick,
 SphericalRegion -> True,
 Method -> {"RotationControl" -> "Globe"},
 ImageSize -> {500, 500},
 Background -> Black
 ]

The option PlotStyle -> {Thick} is causing the issue. So how can I have a thick style for all curves, and yet still get various colors for them? I need the default colors palette for the curves.

$\endgroup$

4 Answers 4

4
$\begingroup$

Try this

    vec[t_, x_, y_, z_] := {x t, y t, z t}

x0[n_] := RandomReal[{-10, 10}]
y0[n_] := RandomReal[{-10, 10}]
z0[n_] := RandomReal[{-10, 10}]

vectors[t_] := Table[vec[t, x0[n], y0[n], z0[n]], {n, 1, 10}];

styles = Table[{Hue[0.1*n], Thickness[0.005]}, {n, 1, 10}];

randVectors = 
 ParametricPlot3D[Evaluate@vectors[t], {t, -30, 30}, 
  PlotStyle -> styles, Background -> Black, Boxed -> False, 
  Axes -> None]

Show[randVectors, PlotRange -> Automatic, SphericalRegion -> True, 
 Method -> {"RotationControl" -> "Globe"}, ImageSize -> {500, 500}]

enter image description here

Have fun!

$\endgroup$
1
  • $\begingroup$ This is a great one. Love it! $\endgroup$
    – Cham
    Jan 7, 2021 at 17:49
4
$\begingroup$

Ok, I've found the solution: Just use BaseStyle -> Thick, instead of PlotStyle -> Thick.

$\endgroup$
1
$\begingroup$

To simplify the generation of vectors

$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

Clear["Global`*"]

vec[t_, x_, y_, z_] := {x t, y t, z t}

SeedRandom[1234];
xyz = RandomReal[{-10, 10}, {10, 3}];

randVectors = ParametricPlot3D[
   Evaluate[vec[t, ##] & @@@ xyz], {t, -30, 30},
   PlotStyle -> Thick];

Show[randVectors,
 Axes -> None,
 BoxStyle -> Thick,
 SphericalRegion -> True,
 Method -> {"RotationControl" -> "Globe"},
 ImageSize -> {500, 500},
 Background -> Black]

enter image description here

$\endgroup$
0
$\begingroup$

Another approach is to remove the thickness specifications from each line that were generated by ParametricPlot3D (as well as the annotations that you may not need), and add yours:

Show[
 randVectors /. 
  Annotation[{color_, ___, l : _Line}, ___] :> {color, Thickness[0.02], l},

 Boxed -> False,(*instead of BoxStyle -> Thick*)
 
 PlotRange -> Automatic, Axes -> None,
 SphericalRegion -> True,
 Method -> {"RotationControl" -> "Globe"},
 ImageSize -> {500, 500},
 Background -> Black
]

I would also recommend using Boxed -> False to get rid of the encompassing box, which was showing on top of some of your lines as a black "blot" in your plot.

$\endgroup$
1
  • $\begingroup$ I need the box, in my full code, to help visualization on a black background. $\endgroup$
    – Cham
    Jan 7, 2021 at 16:30

Your Answer

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

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