Plotting arrows at the edges of a curve

后端 未结 3 1491
死守一世寂寞
死守一世寂寞 2020-12-28 10:01

Inspired by this question at ask.sagemath, what is the best way of adding arrows to the end of curves produced by Plot, ContourPlot

3条回答
  •  误落风尘
    2020-12-28 10:33

    The following seems to work, by sorting the segments first:

    f[x_] := {E^-x^2, Sin[10 x], Sign[x], Tan[x], UnitBox[x], 
                 IntegerPart[x], Gamma[x],
                 Piecewise[{{x^2, x < 0}, {x, x > 0}}], {x, x^2}}; 
    
    arrowPlot[f_] := 
     Plot[{#}, {x, -2, 2}, Axes -> False, Frame -> True, PlotRangePadding -> .2] /.
    
     {Hue[qq__], a___, x___Line} :> {Hue[qq], a, SortBy[{x}, #[[1, 1, 1]] &]} /. 
    
     {a___,{Line[x___], d___, Line[z__]}} :> 
                               List[Arrowheads[{-.06, 0}], a, Arrow[x], {d}, 
                                                 Arrowheads[{0, .06}], Arrow[z]] /. 
    
     {a___,{Line[x__]}}:> List[Arrowheads[{-.06, 0.06}], a, Arrow[x]] & /@ f[x];  
    
    arrowPlot[f]
    

提交回复
热议问题