111
🧩 Syntax:
import matplotlib.pyplot as plt
x=np.array([1,2,3,4,5])
y=np.array([-10,30,120,55,100])
plt.title('basha')
plt.xlabel('x')
plt.ylabel('y')
plt.plot(x,y)
plt.show
import numpy as npa
import matplotlib.pyplot as plt
# Generate x values (4 cycles of sine wave)
x = npa.linspace(0, 4 * 2 * npa.pi, 1000) # 4 cycles, 1000 points
y = npa.sin(x) # Sine wave
# Plot the sine wave
plt.plot(x, y)
plt.title("4 Cycles of a Sine Wave")
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.grid(True)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# Define the x values
x = np.linspace(-10, 10, 500)
# Define the two functions
y1 = np.cos(x) # First function: y = cos(x)
y2 = np.sin(x) # Second function: y = sin(x)
# Plot the functions
plt.figure(figsize=(8,5))
plt.plot(x, y1, label="y = cos(x)", color="blue")
plt.plot(x, y2, label="y = sin(x)", color="red")
# Add labels, title, and legend
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("Plot of Two Functions")
plt.legend()
# Show the plot
plt.grid(True)
plt.show()
help(plt.plot)
title_font ={'family':'serif','color':'blue','weight':'normal','size':20}
plt.title("st line",fontdict=title_font)
x=np.array([0,5,10])
y=np.array([0,50,100])
plt.grid()
plt.plot(x,y,'mv:',linewidth=5,markersize=30)
import matplotlib.pyplot as plt
x=np.array([1,2,3,4,5])
y=np.array([-10,30,120,55,100])
plt.title('basha')
plt.xlabel('x')
plt.ylabel('y')
plt.scatter(x,y)
plt.show
datax=np.random.rand(100)
datay=np.random.rand(100)
plt.plot(datax,datay)
import matplotlib.pyplot as plt
import numpy as np
# Data for plotting
# First subplot
x=np.array([1,2,3,4,5])
y=np.array([-10,30,120,55,100])
plt.subplot(2,2,1) # 2 rows, 2 column
plt.plot(x,y)
# Second subplot
x=np.array([1,2,3,4,5])
y=np.array([-10,30,120,55,100])
plt.subplot(2,2,2) # 2 rows, 2 column
plt.plot(x,y)
# third subplot
x=np.array([1,2,3,4,5])
y=np.array([-10,30,120,55,100])
plt.subplot(2,2,3) # 2 rows, 2 column
plt.plot(x,y)
# fourth subplot
x=np.array([1,2,3,4,5])
y=np.array([-10,30,120,55,100])
plt.subplot(2,2,4) # 2 rows, 2 column
plt.plot(x,y)
plt.show()
plt.title('basha')
plt.xlabel('city')
plt.ylabel('num')
city=np.array(['dahab','loxur','alex'])
num=np.array([5,2,4])
plt.barh(city,num,color="maroon")
plt.title('basha')
plt.xlabel('cars')
plt.ylabel('num')
cars=np.array(['teslA','VERNA','pagani','porche'])
acolors=np.array(['blue','white','pink','green'])
num=([10,60,5,15])
plt.pie(num,labels=cars,colors=acolors)
plt.show()