5
$\begingroup$

I am wondering: why there is no option for VertexOpacity, while there is for VertexColors?

Graphics[Line[Table[{i, 0.02 i}, {i, 1, 5}], VertexColors -> RandomColor[5]]]

I can use Point, specifying coloring and opacity, but how I can connect them?

I want this feature to plot 10,000,000 points (or equivalently 4000 lines), and I realize the time consumption of the line is less than Point.

$\endgroup$
4
  • 1
    $\begingroup$ use VertexColors -> MapThread[Append, {RandomColor[5], RandomReal[{0, 1}, 5]}]? $\endgroup$
    – kglr
    Commented Sep 26, 2020 at 4:08
  • 1
    $\begingroup$ or VertexColors -> (Opacity[#, Red] & /@ RandomReal[{0, 1}, 5])? $\endgroup$
    – kglr
    Commented Sep 26, 2020 at 4:09
  • $\begingroup$ @kglr, Thanks it seems it works. How can I close this topic? $\endgroup$ Commented Sep 26, 2020 at 4:26
  • 1
    $\begingroup$ If you want, you can write an answer to your own question based on what @kglr wrote, if you understood what he meant. $\endgroup$ Commented Sep 26, 2020 at 6:04

1 Answer 1

6
$\begingroup$

I prepare the following example based on @kglr comment.

Let's define points as

points = Table[{x, y, Cos[2 x] + Cos[2 y]/2}, {x, 0, 10, 0.1}, {y, 0, 10, 0.1}];

Now plotting points with separate coloring,

Graphics[{Opacity[Abs@#[[3]], 
 Blend[{{-1, Blue}, {0, Yellow}, {1, Red}}, #[[3]]]], 
Point[#[[1 ;; 2]]]} & /@ Flatten[points, 1]]

gives,

enter image description here

using vertexColors,

Graphics[Point[#[[All, 1 ;; 2]], 
VertexColors -> (Opacity[Abs@#, 
     Blend[{{-1, Blue}, {0, Yellow}, {1, Red}}, #]] & /@ #[[All, 
     3]])] & /@ points]

gives,

enter image description here

and if i interpreter it as a line,

Graphics[Line[#[[All, 1 ;; 2]], 
VertexColors -> (Opacity[ Abs@#, 
     Blend[{{-1, Blue}, {0, Yellow}, {1, Red}}, #]] & /@ #[[All, 
     3]])] & /@ points]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ To put it another way: if you want to modify the opacity of Line[] objects, you can always use colors that have a set alpha channel. $\endgroup$ Commented Sep 26, 2020 at 11:18

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.