0% found this document useful (0 votes)
26 views3 pages

Ex 2

The document outlines an exercise to create basic plots using the Matplotlib library in Python. It includes an algorithm and sample code for generating line plots, scatter plots, bar plots, histograms, and pie charts. The exercise concludes with a successful completion of the plotting tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Ex 2

The document outlines an exercise to create basic plots using the Matplotlib library in Python. It includes an algorithm and sample code for generating line plots, scatter plots, bar plots, histograms, and pie charts. The exercise concludes with a successful completion of the plotting tasks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EX.

NO: 2 BASIC PLOTS USING MATPLOTLIB


DATE:

AIM

To draw basic plots in Python program using Matplotlib

ALGORITHM

Step1: Start
Step2: import Matplotlib module
Step3: Create a Basic plots using Matplotlib
Step4: Print the output
Step5: Stop

PROGRAM

import matplotlib.pyplot as plt


import numpy as np

# Data for plotting


x = np.linspace(0, 10, 100)
y = np.sin(x)
y2 = np.cos(x)

# 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.

You might also like