Subplotting of Even, Odd and Prime numbers in Python

MatplotLib subplot

MatplotLib is a library in Python and is a mathematical extension to the Numpy library. Pyplot is a state-based interface to the Matplatlib module that provides a matlab-like interface.

The subplots() function -

Pyplot module of matplotlib library is used to create a figure and a set of subplots.

The MatplotLib subplot () function is called to plot two or more plots in an image. MatplotLib supports all types of subplots, including 2x1 vertical, 2x1 horizontal or 2x2 grid.

plt.axes():

The most basic method of creating axes is to use the plt.axes function. by default it creates a standard axis object that fills the entire character.

The plt.axes figure also takes up the optional argument, which is a list of four numbers in the coordinate system. These numbers represent [left, bottom, width, height] in the figure coordinate system, from 0 on the bottom left of the figure to 1 on the top right of the figure.

For example, by setting the x and y position to 0.65 you can create an inset axis in the upper-right corner of another axis (i.e., 65% of the width and 65% of the height of the figure) and x and y extensions of 0.2 (i.e., the size of the ax in width 20% and 20% of the height of the figure):

ax1 = plt.axes () # Standard axes
ax2 = plt.axes ([0.65, 0.65, 0.2, 0.2])

Example: Subplotting of Even, odd and Prime numbers in Python Programming

Python code:
```import numpy as np
from matplotlib import pyplot as plt
a = np.array([11,12,13,14,15,16,17,18,19])
even=[]
odd=[]
prime=[]
count=0while count<=8:
if(a[count]%2==0):
even.append(a[count])
else:
odd.append(a[count])
count = count + 1count = 0while count <= 8:
fact = 2    flag = 0    current = a[count]
while fact<current:
if (a[count]%fact==0):
flag = 1            break        fact = fact + 1        if flag==1:
print(a[count])
print('number is not prime')
else:
prime.append(a[count])
count = count + 1print('list of odd numbers')
print(odd)
print('list of even numbers')
print(even)
print('list of prime numbers')
print(prime)
plt.figure()
plt.subplot(311)
plt.plot(even,'ro')
plt.xticks(range(0,5),[1,2,3,4,5])
plt.xlabel('element number')
plt.ylabel('element value')
plt.title('graph of even numbers')
plt.subplot(312)
plt.plot(odd,'b*')
plt.xticks(range(0,5),[1,2,3,4,5])
plt.xlabel('element number')
plt.ylabel('element value')
plt.title('graph of odd numbers')
plt.subplot(313)
plt.plot(prime,'g^')
plt.xticks(range(0,5),[1,2,3,4,5])
plt.xlabel('element number')
plt.ylabel('element value')
plt.title('graph of prime numbers')
plt.tight_layout()
plt.show()

Subplotting of Even, Odd and Prime numbers in Python

Recommended Post:
Program to check whether the number is prime or not
Plotting of even, odd, prime numbers from a list
Subplot of even, odd and prime numbers from a list
Python Program to print Arithmetic Progress series
Program to find even and odd numbers from the list
Program to check whether a number is odd or even

Python Program to print and plot the Fibonacci Series

Program to find sum of the elements in Python

Python Program to print Geometric Progress series
Python Program to Print Harmonic Progress series

```