Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to handle an asymptote/discontinuity with Matplotlib?
To handle an asymptote/discontinuity with matplotlib, we can take the following steps −
Create x and y data points using numpy.
Turn off the axes plot.
Plot the line with x and y data points.
Add a horizontal line across the axis, x=0.
Add a vertical line across the axis, y=0.
Place legend for the curve y=1/x.
To display the figure, use show() method.
Example
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-1, 1, 100)
y = 1 / x
plt.axis('off')
plt.plot(x, y, label='y=1/x')
plt.axhline(y=0, c='red')
plt.axvline(x=0, c='red')
plt.legend(loc='upper left')
plt.show()
Output

Advertisements