Skip to main content
added 759 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Update: using the second approach to make a function:

ClearAll[modifyFenceWidth]
modifyFenceWidth[arg : h_[w_] | w_] := # /.  Switch[Head[arg], 
     Offset, Offset[{a_, _}, b_] :> Offset[{ w  Sign[a]/2 , 0}, b], 
     Real, Offset[{a_, _}, {b_, c_}] :> {b + w/2 Sign[a], c},
     Scaled, Offset[{a_, _}, {b_, c_}] :> 
       {b + w Abs[Subtract @@ PlotRange[#][[1]]]/2 Sign[a], c}] &

Examples:

you can specify the fence width in user units, printer's points or as fraction of the plot width:

Row[Labeled[modifyFenceWidth[#] @ llp2, 
     Style["modifyFenceWidth @ " <> ToString[#], 18], Top] & /@ 
   {.4, Offset @ 20, Scaled @ .1}, Spacer[10]]

enter image description here

Update: using the second approach to make a function:

ClearAll[modifyFenceWidth]
modifyFenceWidth[arg : h_[w_] | w_] := # /.  Switch[Head[arg], 
     Offset, Offset[{a_, _}, b_] :> Offset[{ w  Sign[a]/2 , 0}, b], 
     Real, Offset[{a_, _}, {b_, c_}] :> {b + w/2 Sign[a], c},
     Scaled, Offset[{a_, _}, {b_, c_}] :> 
       {b + w Abs[Subtract @@ PlotRange[#][[1]]]/2 Sign[a], c}] &

Examples:

you can specify the fence width in user units, printer's points or as fraction of the plot width:

Row[Labeled[modifyFenceWidth[#] @ llp2, 
     Style["modifyFenceWidth @ " <> ToString[#], 18], Top] & /@ 
   {.4, Offset @ 20, Scaled @ .1}, Spacer[10]]

enter image description here

deleted 360 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

This is clearly a bug.

  In addition to the weird fence shape, the scaling behavior is also changed: fence widths change when the plot is resized.

A work-around is to post-process the output to straighten the fence lines and make fence widths independent of image size:

ClearAll[repairFences]
repairFencesrepairFences[w_] := Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
    (Line[Thread[Line[{#[[;;Offset[{-w 2,72 /2 , 1]]0}, #[[1,1]]], 1Offset[{w 72/2 , 2]]0}]], &#[[1,1]]]}]& /@ 
    Partition[x, 2]), All] &;&

llp = ListLogPlot[Table[{i, Around[1 + Sin[i], 0.1 + 0.1 Cos[i]]}, {i, 0, 10,  1.0}],
       PlotRange -> {All, {0.01, 10}},
            IntervalMarkers -> "Fences",
            IntervalMarkersStyle -> <|"FenceWidth" -> .3|>
       ] 

Row[Show[repairFences @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

enter image description here

To get fence widths independent of image size we change the replacement rule:

ClearAll[repairFences2]
repairFences2[w_] := Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
  (Line[{Offset[{-w 72 /2 , 0}, #[[1,1]]], Offset[{w 72/2 , 0}, #[[1,1]]]}]& /@ 
    Partition[x, 2]), All] &

Row[Show[repairFences2[Row[Show[repairFences[.3] @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

This is clearly a bug.

  In addition to the weird fence shape, the scaling behavior is also changed: fence widths change when the plot is resized.

A work-around is to post-process the output to straighten the fence lines:

ClearAll[repairFences]
repairFences = Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
    (Line[Thread[{#[[;; 2, 2, 1]], #[[1, 1, 2]]}]] & /@ Partition[x, 2]), All] &;

llp = ListLogPlot[Table[{i, Around[1 + Sin[i], 0.1 + 0.1 Cos[i]]}, {i, 0, 10,  1.0}],
       PlotRange -> {All, {0.01, 10}},
        IntervalMarkers -> "Fences",
        IntervalMarkersStyle -> <|"FenceWidth" -> .3|>
       ] 

Row[Show[repairFences @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

enter image description here

To get fence widths independent of image size we change the replacement rule:

ClearAll[repairFences2]
repairFences2[w_] := Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
  (Line[{Offset[{-w 72 /2 , 0}, #[[1,1]]], Offset[{w 72/2 , 0}, #[[1,1]]]}]& /@ 
    Partition[x, 2]), All] &

Row[Show[repairFences2[.3] @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

This is clearly a bug. In addition to the weird fence shape, the scaling behavior is also changed: fence widths change when the plot is resized.

A work-around is to post-process the output to straighten the fence lines and make fence widths independent of image size:

ClearAll[repairFences]
repairFences[w_] := Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
  (Line[{Offset[{-w 72 /2 , 0}, #[[1,1]]], Offset[{w 72/2 , 0}, #[[1,1]]]}]& /@ 
    Partition[x, 2]), All] &

llp = ListLogPlot[Table[{i, Around[1 + Sin[i], 0.1 + 0.1 Cos[i]]}, {i, 0, 10,  1.0}],
       PlotRange -> {All, {0.01, 10}},
       IntervalMarkers -> "Fences",
       IntervalMarkersStyle -> <|"FenceWidth" -> .3|>
       ] ;

Row[Show[repairFences[.3] @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]
added 685 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

In addition to the weird fence shape, the scaling behavior is also changed: fence widths change when the plot is resized.

A work-around is to post-process the output to fixstraighten the fence lines:

ClearAll[repairFences]
repairFences = Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
    (Line[Thread[{#[[;; 2, 2, 1]], #[[1, 1, 2]]}]] & /@ Partition[x, 2]), All] &;

repairFences @ 
 llp = ListLogPlot[Table[{i, Around[1 + Sin[i], 0.1 + 0.1 Cos[i]]}, {i, 0, 10,  1.0}],
       PlotRange -> {All, {0.01, 10}},
       IntervalMarkers -> "Fences",
       IntervalMarkersStyle -> <|"FenceWidth" -> .3|>
       ] 

Row[Show[repairFences @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

enter image description hereenter image description here

To get fence widths independent of image size we change the replacement rule:

ClearAll[repairFences2]
repairFences2[w_] := Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
  (Line[{Offset[{-w 72 /2 , 0}, #[[1,1]]], Offset[{w 72/2 , 0}, #[[1,1]]]}]& /@ 
    Partition[x, 2]), All] &

Row[Show[repairFences2[.3] @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

enter image description here

A work-around is to post-process the output to fix the fence lines:

ClearAll[repairFences]
repairFences = Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
    (Line[Thread[{#[[;; 2, 2, 1]], #[[1, 1, 2]]}]] & /@ Partition[x, 2]), All] &;

repairFences @ 
   ListLogPlot[Table[{i, Around[1 + Sin[i], 0.1 + 0.1 Cos[i]]}, {i, 0, 10,  1.0}],
       PlotRange -> {All, {0.01, 10}},
       IntervalMarkers -> "Fences",
       IntervalMarkersStyle -> <|"FenceWidth" -> .3|>
       ] 

enter image description here

In addition to the weird fence shape, the scaling behavior is also changed: fence widths change when the plot is resized.

A work-around is to post-process the output to straighten the fence lines:

ClearAll[repairFences]
repairFences = Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
    (Line[Thread[{#[[;; 2, 2, 1]], #[[1, 1, 2]]}]] & /@ Partition[x, 2]), All] &;

llp = ListLogPlot[Table[{i, Around[1 + Sin[i], 0.1 + 0.1 Cos[i]]}, {i, 0, 10,  1.0}],
       PlotRange -> {All, {0.01, 10}},
       IntervalMarkers -> "Fences",
       IntervalMarkersStyle -> <|"FenceWidth" -> .3|>
       ] 

Row[Show[repairFences @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

enter image description here

To get fence widths independent of image size we change the replacement rule:

ClearAll[repairFences2]
repairFences2[w_] := Replace[#,  Line[x_] /; Length[Dimensions@x] ==  3 :>
  (Line[{Offset[{-w 72 /2 , 0}, #[[1,1]]], Offset[{w 72/2 , 0}, #[[1,1]]]}]& /@ 
    Partition[x, 2]), All] &

Row[Show[repairFences2[.3] @ llp, ImageSize -> #]& /@ {200, 500}, Spacer[10]]

enter image description here

added 83 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
deleted 1 character in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 451 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 189 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
deleted 18 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 523 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading