Python Program to Plot Bessel Function

This python program plots modified Bessel function of first kind, and of order 0 using numpy and matplotlib.

Python Source Code: Bessel Function


# Importing Required Libraries
import numpy as np
from matplotlib import pyplot as plt

# Generating time data using arange function from numpy
x = np.arange(0, 3, 0.01)

# Finding amplitude at each time using np.i0 function
amplitude = np.i0(x)

# Plotting x vs amplitude using plot function from pyplot
plt.plot(x, amplitude, 'r')

# Settng title for the plot in blue color
plt.title('Modified Bessel - First Kind - Order 0', color='r')

# Setting x axis label for the plot
plt.xlabel('x'+ r'$\rightarrow$')

# Showing grid
plt.grid()

# Highlighting axis at x=0 and y=0
plt.axhline(y=0, color='b')
plt.axvline(x=0, color='b')

# Finally displaying the plot
plt.show()

Output

Modified Bessel Function Using Python Output
Figure: Modified Bessel Function Using Python Output

Note:

According to numpy documentation, the scipy implementation of i0() is recommended over this function.