# Plotting x and y asymptotes of a rational function

**URL:** <https://community.wolfram.com/t/plotting-x-and-y-asymptotes-of-a-rational-function/4488>\
**Category:** Questions\
**Tags:** mathematica, graphics-and-visualization\
**Created:** [January 8, 2015, 9:52am UTC](https://community.wolfram.com/t/plotting-x-and-y-asymptotes-of-a-rational-function/4488 "2015-01-08T09:52:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![torjusti](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@torjusti](https://community.wolfram.com/u/torjusti)\
**Post date:** [January 8, 2015, 9:52am UTC](https://community.wolfram.com/t/plotting-x-and-y-asymptotes-of-a-rational-function/4488/1 "2015-01-08T09:52:55Z")

</div>

Hello,

I’ve been trying to plot this rational function and illustrate the asymptotes of it, but I don’t know how to get both the asymptotes plotted in together with the function.

```
f(x_):=(3x-1)/(2x+6)

```

 ![vbhLcg2.png](https://global.discourse-cdn.com/wolfram/original/2X/7/761660754c246c7ed3f7c3d9586f5ede307a7d66.png)

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [January 8, 2015, 10:22am UTC](https://community.wolfram.com/t/plotting-x-and-y-asymptotes-of-a-rational-function/4488/2 "2015-01-08T10:22:52Z")

</div>

You get a graph like that with

```
f[x_] := (3 x - 1)/(2 x + 6);
Plot[{f[x], 3/2}, {x, -11, 7}, Exclusions -> {x == -3}, 
 ExclusionsStyle -> Red, PlotStyle -> {Black, Red}, PlotRange -> 10, 
 AspectRatio -> Automatic]

```

You can insert the labels with Epilog:

```
f[x_] := (3 x - 1)/(2 x + 6);
Plot[{f[x], 3/2}, {x, -11, 7}, Exclusions -> {x == -3}, 
 ExclusionsStyle -> Red, PlotStyle -> {Black, Red}, PlotRange -> 10, 
 AspectRatio -> Automatic, 
 Epilog -> {Text[x == -3, {-5, -8}], Text[y == 1.5, {5, 2}]}]

```

---

<div class="post-metadata">

**Author:** ![lowriniak](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/lowriniak/32/15046_2.png) [@lowriniak](https://community.wolfram.com/u/lowriniak)\
**Post date:** [January 8, 2015, 10:38am UTC](https://community.wolfram.com/t/plotting-x-and-y-asymptotes-of-a-rational-function/4488/3 "2015-01-08T10:38:27Z")

</div>

Hi Torjus,  
I had a quick look, and there are a few ways of doing this. When you just plot the function like this:

`Plot[(3 x - 1)/(2 x + 6), {x, -10, 6}]`

you get an output with the vertical asymptote:

 ![ScreenShot2015-01-08at10.26.21.png](https://global.discourse-cdn.com/wolfram/original/3X/1/d/1d5c2a2fd3c5fa612a1f427d8b96a8f5428ffd91.png)

You can then just add another function to plot of 1.5, like this:

```
Plot[{(3 x - 1)/(2 x + 6), 1.5}, {x, -10, 6}]

```

This is fine, but if you want both asymptotes to be a different graphics primitive we will have to try something else. You can also use GridLines, though I find this a bit clunky:

```
Plot[(3 x - 1)/(2 x + 6), {x, -10, 6},GridLines->{{-3,0},{0,1.5}}]

```

 ![ScreenShot2015-01-08at10.31.29.png](https://global.discourse-cdn.com/wolfram/original/2X/e/eae40261a59772c4d72956107fed0b2c4c4b5ad4.png)

OK, so now we have both asymptotes, but still the vertical one from the original plot. To stop this from showing up use Exclusions (an option in plot):

```
Plot[(3 x - 1)/(2 x + 6), {x, -10, 6},Exclusions->{x==-3},GridLines->{{-3,0},{0,1.5}}]

```

Another way, and my preferred method, is to use the option Epilog to add a Line primitive onto the plot. You can then style the asymptotes separately to make them more clear:

```
Plot[{(3 x - 1)/(2 x + 6), 1.5}, {x, -10, 6}, 
 PlotStyle -> {Black, Red}, Exclusions -> {x == -3}, 
 Epilog -> {Red, Line[{{-3, -100}, {-3, 100}}]}]

```

 ![ScreenShot2015-01-08at10.34.24.png](https://global.discourse-cdn.com/wolfram/original/3X/c/6/c629a98f9856292865a38c882426d851ebc3b72c.png)

From here, you can use labelling options to add in your asymptote labels.

I hope this helps!

Nia Knibbs Vaughan
