6
$\begingroup$

I wanted to use Around to plot values with uncertainties in ListPlot. But when I used PlotStyle to change the color, it only changes the color of the dots but not the error bars; for example

ListPlot[{Around[1, 0.1]}, PlotStyle -> Red]

How can I also change the color of the error bars?

$\endgroup$
2
  • $\begingroup$ This is a version-specific problem. The error bar is Red in v12.0 and v12.2 on my Mac; however, in v12.1.1 I need to use ListPlot[{Around[1, 0.1]}, PlotStyle -> Red] /. RGBColor[__] :> Red $\endgroup$
    – Bob Hanlon
    May 14, 2021 at 12:13
  • $\begingroup$ See also IntervalMarkersStyle $\endgroup$
    – MelaGo
    May 14, 2021 at 22:36

1 Answer 1

7
$\begingroup$

With v12.0 or v12.2 the color of the error bars match the PlotStyle; however, with v12.1.1

$Version

(* "12.1.1 for Mac OS X x86 (64-bit) (June 19, 2020)" *)

ListPlot[{
  {{1, Around[1, 0.1]}, {3, Around[2, 0.1]}},
  {{2, Around[2, 0.1]}, {4, Around[1.5, 0.1]}}}, 
 PlotStyle -> {Red, Darker@Green},
 PlotLegends -> Automatic]

enter image description here

A workaround is to replace each RGBColor with the associated PlotStyle

Legended[
 Show[
  ListPlot[
    {{1, Around[1, 0.1]}, {3, Around[2, 0.1]}}, PlotStyle -> Red] /. 
   RGBColor[__] :> Red,
  ListPlot[
    {{2, Around[2, 0.1]}, {4, Around[1.5, 0.1]}}, 
    PlotStyle -> Darker@Green] /. RGBColor[__] :> Darker@Green,
  PlotRange -> All],
 PointLegend[{Red, Darker@Green}, Automatic]]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Hi Bob, Thanks a lot for your comment and your answer! Indeed I was using 12.1.1 and once I upgraded to 12.2.0 it works. $\endgroup$
    – H. Zhou
    May 14, 2021 at 13:55

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.