Ex 2
Ex 2
AIM
ALGORITHM
Step1: Start
Step2: import Matplotlib module
Step3: Create a Basic plots using Matplotlib
Step4: Print the output
Step5: Stop
PROGRAM
# Line plot
plt.figure(figsize=(8, 6))
plt.plot(x, y, label='sin(x)', color='blue')
plt.plot(x, y2, label='cos(x)', color='red')
plt.title("Basic Line Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend()
plt.grid(True)
plt.show()
# Scatter plot
plt.figure(figsize=(8, 6))
plt.scatter(x, y, color='green', label='sin(x)')
plt.title("Basic Scatter Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.legend()
plt.grid(True)
plt.show()
# Bar plot
categories = ['A', 'B', 'C', 'D', 'E']
values = [10, 15, 7, 10, 5]
plt.figure(figsize=(8, 6))
plt.bar(categories, values, color='purple')
plt.title("Basic Bar Plot")
plt.xlabel("Categories")
plt.ylabel("Values")
plt.grid(True)
plt.show()
# Histogram
data = np.random.randn(1000) # Random data for the histogram
plt.figure(figsize=(8, 6))
plt.hist(data, bins=30, color='orange', edgecolor='black')
plt.title("Basic Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.grid(True)
plt.show()
# Pie chart
sizes = [30, 20, 25, 25]
labels = ['A', 'B', 'C', 'D']
plt.figure(figsize=(8, 6))
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)
plt.title("Basic Pie Chart")
plt.show()
OUTPUT
RESULT:
Thus the basic plots using Matplotlib in Python program was successfully
completed.