Program to Plot Arithmetic progression series in Python

Program to Plot Arithmetic progression series


In this, we discuss Arithmetic Progression series and check how to plot Arithmetic Progression series in Python Programming using Matplotlib.



Arithmetic progression series


In mathematics, arithmetic progress (AP) or arithmetic is a series of numbers, i.e. the difference between consecutive terms is constant. The difference here is the second minus the first. For example, 5, 7, 9, 11, 13, 15,. . . Arithmetic progression with a simple difference of 2.

If you want to know more about the Arithmetic progression series then check the post given below:

Python program to print Arithmetic Progression series

If you are new to Python Programming also check the links given below. So that you can easily understand the Program to Plot Arithmetic progression series.


Basics of Python
Python Libraries

After learning all these topic now we moved to Plot the Arithmetic Progression series.

Python Code:
# AP seriesimport numpy as np
from matplotlib import pyplot as plt
r = []
a = int(input('enter first term'))
d = int(input('enter common difference'))
n = int(input('enter number of terms'))
y = np.linspace(1,n,n,dtype= int)
print('AP series is:')
i = 1while(i<=n):
    cr = a + (i-1)*d
    r.append(cr)
    i = i+1    print(cr)
print(r)
plt.plot(y,r,'ro')
plt.xlabel('position of terms')
plt.ylabel('values of terms')
plt.title('Graph of A.P Series')
plt.show()
Output:
enter first term 1
enter common difference 2 
enter number of terms 7
AP series is:
1
3
5
7
9
11
13
[1, 3, 5, 7, 9, 11, 13]
Program to Plot Arithmetic progression series
Program to Plot Arithmetic progression series