Adding arrowheads to a piecewise function

Using custom Arrowheads (instead of Epilog) may be slightly more flexible:

ah1 = Arrowheads[{{-0.05}, {0.015, 1, Graphics@{EdgeForm[Blue], White, Disk[]}}}];
ah2 = Arrowheads[{{0.05, 1}, {0.015, 0, Graphics@ Disk[]}}];
pw = Piecewise[{{-x^2, x < 1}, {x + 1, x >= 1}}];

This can be used with a combination of MeshFunctions and MeshShading:

Plot[pw, {x, -2, 3}, PlotStyle -> Blue, 
  MeshFunctions -> {# &}, Mesh -> {{1}}, MeshShading -> {ah1, ah2}, 
  AxesLabel -> {"x", "y"},  PlotRange -> {{-2, 3}, {-4, 4}}, 
  GridLines -> {Range[-2, 3], Range[-4, 4]}, AspectRatio -> 1, 
  ImageSize -> 300, PlotRangePadding -> .01] /. Line -> Arrow

or in PlotStyle after breaking up the Piecewise pieces into two ConditionalExpressions:

Plot[Evaluate[ConditionalExpression @@@ pw[[1]]], {x, -2, 3}, 
  PlotStyle -> {Directive[Blue, ah1], Directive[Blue, ah2]},
  AxesLabel -> {"x", "y"}, PlotRange -> {{-2, 3}, {-4, 4}}, 
  GridLines -> {Range[-2, 3], Range[-4, 4]}, AspectRatio -> 1, 
  ImageSize -> 300, PlotRangePadding -> .01] /. Line -> Arrow

to get

Mathematica graphics


a bit of a hack..

ipart = 0; 
Plot[Piecewise[{{-x^2, x < 1}, {x + 1, x >= 1}}], {x, -2, 3}, 
  PlotStyle -> Blue, 
  Epilog -> {Blue, Arrowheads[{-0.02, 0.02}], PointSize[Large], 
    Point[{{1, -1}, {1, 2}}], {White, PointSize[Medium], 
     Point[{1, -1}]}}, AxesLabel -> {"x", "y"}, 
  PlotRange -> {{-2.5, 3}, {-4.5, 4}}, 
  GridLines -> {Range[-2, 3], Range[-4, 4]}, AspectRatio -> 1, 
  ImageSize -> 300] /. 
 Line[xx_] :> {++ipart; If[ipart == 1, Arrow[Reverse@xx], Arrow[xx]]}

enter image description here

Tags:

Plotting