Program to Plot Geometric progression series in Python

Program to Plot Geometric progression series


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


Geometric Progression series


In mathematics, a geometric sequence is a series with a constant ratio between consecutive terms. Simple examples of the infinite series with finite sums include the geometric series, although not all of them have this property. 

Historically, the geometric sequence played an important role in the early development of the calculus and they continue to be central to the study of series combinations. 


Common ratio



The rules of a geometric series form a geometric progression, i.e. the ratio of consecutive terms in a sequence is constant. This relationship allows the representation of a geometric series by using both the terms r and a. Term r is the common ratio, and a is the first term in the series.

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

Python program to print Geometric Progression series

If you are new to Python Programming also check the list of topics given below. So that you can easily understand the Program to Plot Geometric progression series.



Basics of Python
Python Libraries

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

Python Code:

# GP seriesimport numpy as np
from matplotlib import pyplot as plt
m = []
a = int(input('enter first term'))
r = int(input('enter common ratio'))
n = int(input('enter number of terms'))
y = np.linspace(1,n,n,dtype= int)
print('GP series is:')
i = 1while(i<=n):
    cr = a*(r**(i-1))
    m.append(cr)
    i = i+1    print(cr)
print(m)
plt.plot(y,m,'ro')
plt.xlabel('position of terms')
plt.ylabel('values of terms')
plt.title('Graph of G.P Series')
plt.show()
Output:

enter first term 1
enter common ratio 2
enter number of terms 6
GP series is:
1
2
4
8
16
32
[1, 2, 4, 8, 16, 32]

Program to Plot Geometric progression series in Python
Program to Plot Geometric progression series in Python