2

I am trying to make the plot function to label the x-coordinate of the vertical asymptotes. I also want it red dashed. I tried this but obviously it is not correct:

Plot[(x - 2)/((x - 1) (x + 2)), {x, -8, 8}, ExclusionsStyle -> {Dashing[Small], Red}]
corey979
  • 23,947
  • 7
  • 58
  • 101

2 Answers2

3

As mentioned in the reference page of ExclusionsStyle, the syntax ExclusionsStyle -> {s, sb} uses the style s for the interiors of excluded subregions, and the style sb for the boundaries of excluded subregions.

With the expression ExclusionsStyle -> {Dashing[Small], Red}, and as can be seen from the output, you are making the lines dashed and the four points red. If you want the vertical asymptotes red dashed with no particular style on the points, you should use instead the syntax ExclusionsStyle -> s, and wrap the different style properties in Directive, so that they can be applied to the same graphics primitive.

Doing so, you get the expected result:

Plot[(x - 2)/((x - 1) (x + 2)), {x, -8, 8}, 
     ExclusionsStyle -> Directive[Dashing[Small], Red]
]

enter image description here


Update following comments. In versions prior to 11.0, the excluded regions need to be given explicitly as a value of the option Exclusions in order to get the proper styling:

Plot[(x - 2)/((x - 1) (x + 2)), {x, -8, 8}, 
     Exclusions -> {x == -2, x == 1}, 
     ExclusionsStyle -> Directive[Dashing[Small], Red]
]
(* same output as above *)
2

I guess in versions before 11 like this:

style = {Red, Dashing[Small]};
line1 = Line[{{-2, -10}, {-2, 10}}];
line2 = Line[{{1, -10}, {1, 10}}];

plot = Plot[(x - 2)/((x - 1) (x + 2)), {x, -8, 8}, 
  Exclusions -> {-2, 1}, PlotRange -> {All, {-3, 3}}, 
  Epilog -> {Directive[style], line1, line2}]

enter image description here

corey979
  • 23,947
  • 7
  • 58
  • 101