3
$\begingroup$

How can I make them the same color even when overlapping?
I want to use transparent to some degree.

Plot[{1 + x, 2 - x}, {x, 0, 1}, 
 PlotStyle -> 
  Directive[Red, Thickness[0.03], Opacity[0.3], CapForm["Round"]]]

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ use PlotStyle -> Directive[Blend[{Red, White}, .7], Thickness[0.03], CapForm["Round"]]? $\endgroup$
    – kglr
    Commented Aug 15, 2022 at 20:44

2 Answers 2

4
$\begingroup$

How can I make them the same color even when overlapping?

One possibility?

p1 = Plot[1 + x, {x, 0, 1}, PlotStyle -> 
    Directive[Red, Thickness[0.03], Opacity[0.3], CapForm["Round"]]];
p2 = Plot[2 - x, {x, 0, 1}, PlotStyle -> 
    Directive[Red, Thickness[0.03], Opacity[0.3], CapForm["Round"]]];

ImageCompose[Rasterize[p1], 
 ColorReplace[Rasterize[p2], White -> Transparent]]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ I think I didn't say it clearly. I actually want Opacity for the lines not the background. $\endgroup$
    – hana
    Commented Aug 16, 2022 at 16:06
3
$\begingroup$

You can use a simplified function to mimic alpha blending:

alphaBlend[rgb_RGBColor, alpha_, back_ : White] := Blend[{rgb, back}, 1 - alpha]

Plot[{1 + x, 2 - x}, {x, 0, 1}, 
 PlotStyle -> 
  Directive[alphaBlend[Red, 0.3], Thickness[0.03], 
   CapForm["Round"]]]

Mathematica graphics

You can also account for the background color

Plot[{1 + x, 2 - x}, {x, 0, 1}, 
 PlotStyle -> 
  Directive[alphaBlend[Red, 0.3, LightBlue], Thickness[0.03], 
   CapForm["Round"]], Background -> LightBlue]

Mathematica graphics

(On preview this is basically what @kglr is saying)

$\endgroup$
1
  • $\begingroup$ But this is not transparent, like Opacity[0.3]. I think I didn't say it clearly. I actually want Opacity for the lines not the background. $\endgroup$
    – hana
    Commented Aug 16, 2022 at 16:01

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.