4
$\begingroup$

There are several questions about removing the default vertical lines in a DiscretePlot, but my issue is that I want to show/emphasize the vertical lines in this DiscretePlot. By default they are not showing up. How can I control their appearance?

DiscretePlot[Sin[x], {x, 0, 2 Pi, Pi/8}, ExtentSize -> Full]

enter image description here

$\endgroup$

2 Answers 2

6
$\begingroup$

1. Use the option BaseStyle (or PlotStyle or FillingStyle -- thanks: BrettChampion):

DiscretePlot[Sin[x], {x, 0, 2 Pi, Pi/8}, 
 ExtentSize -> Full, BaseStyle -> EdgeForm[Thick]]

enter image description here

2. Alternatively, use the option ExtentElementFunction:

DiscretePlot[Sin[x], {x, 0, 2 Pi, Pi/8}, ExtentSize -> Full, 
  ExtentElementFunction -> 
   ({Opacity[.5], EdgeForm[{Darker @ Charting`ChartStyleInformation["Color"], Thick}], 
     ChartElementData["Rectangle"][##]} &)]

enter image description here

3. Yet another way: post-process to add EdgeForm[..] before Rectangles:

 DiscretePlot[Sin[x], {x, 0, 2 Pi, Pi/8}, ExtentSize -> Full] /. 
  r_Rectangle :> {Dynamic[EdgeForm[{CurrentValue["Color"], Thick}]],  r}

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ In addition to BaseStyle, you could also use PlotStyle or FillingStyle to set the EdgeForm. $\endgroup$ Jun 24, 2021 at 14:39
5
$\begingroup$

Like this?

DiscretePlot[Sin[x], {x, 0, 2 Pi, Pi/8}, ExtentSize -> Full] /. 
 Line[a_] :> Line[Partition[Flatten[a, 1], 2, 1]]

enter image description here

Or this?

DiscretePlot[Sin[x], {x, 0, 2 Pi, Pi/8}, ExtentSize -> Full] /. 
 Line[a_] :> 
  Function[{p, q}, {EdgeForm[{JoinForm["Round"]}], FaceForm[], 
     Polygon[{p, q, Projection[q, {1, 0}], Projection[p, {1, 0}]}]}] @@@
    Partition[Flatten[a, 1], 2, 1]

enter image description here

$\endgroup$
1
  • $\begingroup$ the second one. thanks. $\endgroup$
    – JohnD
    Jun 26, 2021 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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