Matplotlib is a data visualization library in Python.
The pyplot, a sublibrary of matplotlib, is a collection of functions that helps in creating a
variety of charts. Line charts are used to represent the relation between two data X and Y on a different axis.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = plt.axes()
X-123Y-149
#Printing x vs x square
fig = plt.figure()
ax = plt.axes()
x = np.array([1,2,3,4])
y= x**2 # x^2
ax.plot(x, y);
#Printing x**2 and x**3 in same graph
z=x**3
fig = plt.figure()
ax = plt.axes()
#x vs x^2
ax.plot(x, y,color='blue',linestyle='solid');
#x vs x^3
ax.plot(x, z,color='red',linestyle='dashed');
plt.title("FDS")
plt.xlabel("x")
plt.ylabel("y");
plt.xlim(5,25)
plt.ylim(-1,-10);
plt.show()
Scatter plots are used to observe relationship between variables and uses dots to represent the relationship between them. The scatter()
method in the matplotlib library is used to draw a scatter plot. Scatter plots are widely used to represent relation among variables and how
change in one affects the other.
#Scatter plots
#linspace(start,stop,number of entries)
#x = np.linspace(0, 10, 30)
#y = np.sin(x)
x= np.array([1,2,3,4,5])
y=np.array([2,4,6,8,10])
plt.scatter(x, y, marker='x');
#Using Plot Function
x = np.linspace(0, 10, 30)
y = np.sin(x)
plt.plot(x, y, 'o', color='red');
The errorbar() function in pyplot module of matplotlib library is used to plot y versus x as lines and/or markers with attached errorbars.
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
# example data
#xval = np.arange(1, 4, 0.5)
#yval = np.exp(-xval)
xval= np.array([1,2,3,4,5])
yval=np.array([2,4,6,8,10])
plt.errorbar(xval, yval, xerr = 2, yerr = 1)
plt.title('matplotlib.pyplot.errorbar() function Example')
plt.show()
def search(pat="abc", txt="hello abcedef"):
M = len(pat)
N = len(txt)
# A loop to slide pat[] one by one */
for i in range(N - M ):
j = 0
# For current index i, check
# for pattern match */
while(j < M):
if (txt[i + j] != pat[j]):
break
j += 1
if (j == M):
print("Pattern found at index ", i)
search()
Pattern found at index 6
Start coding or generate with AI.
Could not connect to the reCAPTCHA service. Please check your internet connection and reload to get a reCAPTCHA challenge.