# Adding direction arrows to discrete plot

I wanted a discrete plot of $$y = -\dfrac{3}{2} x$$ and used

  DiscretePlot[-3/2 x, {x, -20, 20}]


I do not like the vertical lines shown in the plot but I did not see an option to get rid of them.

I then did this kludge to get rid of the vertical lines

  ListPlot[Table[{x, -((3 x)/2)}, {x, Table[x, {x, -20, 20, 1}]}]]


I want to add arrowheads showing that the plot continues upward on the left and downward on the right.

I found this answer that uses BaseStyle, but could not figure out how to use it to place arrows at each endpoint showing direction.

  ListPlot[Table[{x, -((3 x)/2)}, {x, Table[x, {x, -20, 20, 1}]}],
BaseStyle -> Arrowheads[{-20, 30, 20, -30}],
PlotStyle -> {Blue, Thick}] /. Line -> Arrow


I wanted something like this

Is there a simple way to do this?

• The option Filling->None removes lines. From your text, it is not clear where you want to have the arrowheads. If it is at the axis add this option: AxesStyle->Directive[Arrowheads[0.005]]. If you have something else in mind, please sketch what you are after. Oct 11, 2023 at 11:53
• @AlexeiBoulbitch: I added an image showing the desired output. Thanks.
– Moo
Oct 11, 2023 at 12:00

One possible way could be:

Clear["Global*"];
c1 = {#, -3/2 #} & /@ Range[20, 21] // N;
c2 = {#, -3/2 #} & /@ Range[-20, -21, -1] // N;

DiscretePlot[-3/2 x, {x, -20, 20}
, Filling -> None
, Epilog -> {
Arrow[c1], Arrow[c2]
}
]


• That works for me! Somehow I missed Filling -> None. Thanks.
– Moo
Oct 11, 2023 at 12:37
addArrowTips = ReplaceAll[Point[x_] :>
{Point[Take[x, {2, -2}]],
Map[Arrow] @ Extract[x, {{{2, 1}}, {{-2, -1}}}]}];


addArrowTips replaces the points at the two ends of a point list with short arrows. We can use it as the option setting for DisplayFunction .

Alternatively, we use it as addArrowTips @ DiscretePlot[...] to post-process DiscretePlot output.

Examples:

DiscretePlot[-3/2 x,
{x, -20, 20},
Filling -> None,


DiscretePlot[{-3/2 x, x^3/100, x^2/5 + 20},
{x, -20, 20},
Filling -> None,


DiscretePlot[{x Sin[2 x], 5 + x Cos[2 x]},
{x, -6, 6, Pi/40},
Filling -> None,
PlotStyle -> PointSize[Medium],
`