Universidad de Dagupan
School of Engineering
Name: NUMERICAL Date Performed:
Group: SOLUTIONS Date Submitted:
LABORATORY ACTIVITY NO.1
The NumPy & Matplotlib
OBJECTIVES:
To learn how to use Matplotlib and NumPy in Python to create
plots and visualize data.
INSTRUCTIONS:
Before we begin, make sure you have Matplotlib and NumPy
installed. If you haven't installed them yet, you can do so
using pip
PROCEDURE 1: GETTING STARTED
1. Let's start by importing the necessary libraries
2. Let's start by defining the function f ( x )=x 2.
3. Now, let's generate some data points to plot the function.
The code will Generate 100 points between -5 and 5.
Universidad de Dagupan
School of Engineering
4. Plot the Function
PROCEDURE 2. CUSTOMIZING THE PLOT
1. In procedure 1, step number 4, add vertical and horizontal
lines at x = 0, & y = 0 respectively. Put this before the
plt.grid(True) or plt.show() command.
2. You can change the colors and styles of the lines in the
plot.
Here are some linestyle you can use.
Solid ‘-‘
Dotted ‘:’
Dashed ‘--'
Dashdot ‘-.’
3. For annotations, you can use plt.text(). Also, you can add
as well.
PROCEDURE 3. PLOTTING
Universidad de Dagupan
School of Engineering
Graph the following function f(x) using Python plotting libraries
(e.g., Matplotlib).
1. f(x) = x3-x, show the graph between -3 to 5 with 100
points.
Set the line color to blue and line style to dashed.
Add labels to the x-axis as “x” and y-axis as “y”.
Add a title to the plot as “f(x) = x3-x”.
Add a legend to the plot.
2. Plot the function , over the range [-2,2] with
200 points.
Set the line color to red and line style to solid.
Add labels to the x-axis as "x" and y-axis as "g(x)".
Add a title to the plot as "Plot of g(x) = 1 / (x^2 +
1)".
Add a legend to the plot.
Data and Results with Codes: