Experiment No.
Student Name: Gautam UID: 24MCI10233
Branch: MCA Section/Group: MAM-4A
Semester: 1st Date of Performance: 1st October 2024
Subject Name: Python Programming Subject Code: 24CAH-606
Q. (a) Write a python program to generate histogram using matplotlib. The graph should
be properly labelled.
Aim/Overview of the practical: The aim of this practical is to understand the basic concept of
plotting histogram using matplotlib. This will enhace your analytical skills.
1. Task to be done:
• First we have to import the matplotlib library.
• Secondly,we have to define the data.
• Then we have to crate histogram and adding labels and title into it.
• Lastly, we have to display the histogram.
2. Code for experiment/practical:
import matplotlib.pyplot as plt
import numpy as np
# Sample data
data = np.random.randn(1000) # Generate 1000 random numbers from a normal distribution
# Create the histogram
plt.hist(data, bins=20, color='black', edgecolor='red')
# Add labels and title
plt.xlabel('Students')
plt.ylabel('marks')
plt.title('Histogram of result')
# Display the histogram
plt.show()
3. Result/Output/Writing Summary:
• Learning outcomes (What I have learnt):
Understand the basic concepts of histogram.
Learned to plot the histogram and applying some themes on it like color and border etc.
Understanding and becoming familiar with the matplotlib library.
(b) Write a Python program to plot the function y = x2 using the matplotlib libraries.
Aim/Overview of the practical: The aim of this practical is to understand how to plot
mathematical functions using Python's matplotlib library. the function y = x2 is plotted, which
will allow you to visualize the behavior of the quadratic equation.
1. Task to be done:
• Firstly, we have to import the matplotlib library.
• Then we have to generate data points and calculate y values.
• Then we have to plot the function and add labels and title to it.’
• Lastly, we have to display the data.
2.Code for experiment/practical:
import matplotlib.pyplot as plt
import numpy as np
# Generate data points x =
np.linspace(10, 50, 100)
y=x**2
plt.plot(x, y, label="y = x^2", color="red")
# Add labels and title
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("Plot of y = x^2")
# Add a legend
plt.legend()
plt.grid(False)
plt.show()
3.Result/Output/Writing Summary:
• Learning outcomes (What I have learnt):
• Learned how to apply mathematical functions using python library.
• Get more familiarize with matplotlib library.
• Learned to visualize the behaviour of quadratic equation.
• Understand the basic use of numpy for basic use of numerical operations.