Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot asymptotes?

I've followed a little tutorial that's got me near where I want, but It's not quite there and I'm not sure how to make the next step with it.
Here' my figure as it currently stands:

original

I'm not sure how to go about plotting the asymptotes into this graph though.

I'm thinking that I need to create a variable called Y that's a vertical line and then plot lines off that? I'm not sure if that's correct though

How would I go about creating lines for the asymptotes in this case?

EDIT

This is my code:

import pylab as pl
import numpy as np
import matplotlib.pyplot as plt

"""
This is all from the tutorial located at :
http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html
"""

pl.figure(figsize=(10, 6), dpi=80)
pl.subplot(1, 1, 1)
X = np.linspace(-5, 5, 500, endpoint=True)
C = (1/X**2)-5
P = X - X - 0.1

pl.xlim(X.min() * 1.1, X.max() * 1.1)
pl.ylim(C.min() * 1.1, C.max() * 1.1)

"""
Alters the position of the axis - moves them to the centre
"""
ax = pl.gca()  # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))

pl.plot(X, C, color="blue",  linewidth=4, linestyle="-", 
              label="y = 4 - 1/x^2")

pl.legend(loc='upper left')


for label in ax.get_xticklabels() + ax.get_yticklabels():
    label.set_fontsize(16)
    label.set_bbox(dict(facecolor='white', edgecolor='None', alpha=0.65))

plt.ylim((-7,20))

plt.show()
like image 221
baxx Avatar asked Sep 30 '22 05:09

baxx


1 Answers

You can add a vertical line using vlines.

For your example you could add a vertical line at x = 3 with the following:

ylim = ax.get_ylim()
plt.vlines(3, ylim[0], ylim[1])

This needs be inserted before plt.show(). Similarly, hlines will add horizontal lines.

like image 150
Molly Avatar answered Oct 12 '22 10:10

Molly