0% found this document useful (0 votes)
2 views

Programs

The document provides examples of creating various plots using Matplotlib, including a scatter plot for subject marks, a line plot for temperatures in different cities, and a bar plot for country-wise medals. It also includes instructions for reading a CSV file with Pandas, displaying rows, and sorting data. The code snippets demonstrate basic data visualization and manipulation techniques.

Uploaded by

Mohak Perumandla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programs

The document provides examples of creating various plots using Matplotlib, including a scatter plot for subject marks, a line plot for temperatures in different cities, and a bar plot for country-wise medals. It also includes instructions for reading a CSV file with Pandas, displaying rows, and sorting data. The code snippets demonstrate basic data visualization and manipulation techniques.

Uploaded by

Mohak Perumandla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Scatter Plot:

import matplotlib.pyplot as plt


marks = [80, 75, 62, 90, 30]
subjects = ['Math', 'Hindi', 'English', 'AI', 'Science']
plt.scatter(subjects, marks, color='red')
plt.title("Subject Marks")
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.show()

Line plot:
import matplotlib.pyplot as plt
temp = [45, 25, 35, 27, 30]
cities = ['Delhi', 'Assam', 'Chennai', 'Hyderabad', 'Goa']
plt.plot(cities, temp, c='blue')
plt.title("Temperature in Different Cities")
plt.xlabel("Cities")
plt.ylabel("Temperature")
plt.show()

Bar Plot:
import matplotlib.pyplot as plt
medals = [45, 25, 35, 27, 30]
countries = ['Delhi', 'Assam', 'Chennai', 'Hyderabad', 'Goa']
plt.bar(countries, medals, color='yellow')
plt.title("Country-wise Medals")
plt.xlabel("Countries")
plt.ylabel("Medals")
plt.show()

# To read the CSV file into a variable


s = pd.read_csv("<path of the CSV file>") # Replace <path of the CSV file> with your actual
file path
# To print the first five rows
print(s.head())
# To print the top ten rows
print(s.head(10))
# To sort the rows by a specific column in ascending order
s_sorted = s.sort_values(by='Name') # For ascending order (default)
# To sort the rows by a specific column in descending order
s_sorted_desc = s.sort_values(by='Name', ascending=False)
# To print the last five rows
print(s.tail())
# To print the last ten rows
print(s.tail(10))

You might also like