PLOTTING WITHOUT DATA
USING PYTHON MODULES
© H. Chiname 2021. Version 03
INTRODUCTION
So far we have only plotted with data.
As already mentioned in the previous lecture, it is possible to
plot without data.
The plots will be the result of different types of formulae and
equations.
To do this, we take advantage of the capabilities of different
modules, mostly pyplot and numpy.
The two modules are complementary to each other in that:
while Numpy is good at manipulating data, formulas, and
equations;
Pyplot takes care of the plotting part.
© H. Chiname 2021. Version 03
PLOTTING WITHOUT DATA
Forour purposes we will plot:
Line graphs;
Histograms;
Bar graphs;
Scatterplots; and
3-dimensional plots.
© H. Chiname 2021. Version 03
ACTIVITY 1: PLOTTING A LINE GRAPH
Find
any suitable equation and plot it in
Matplotlib
© H. Chiname 2021. Version 03
ACTIVITY 1 SOLUTION: PLOTTING A LINE GRAPH
© H. Chiname 2021. Version 03
ACTIVITY 1 SOLUTION: PLOTTING A LINE GRAPH
© H. Chiname 2021. Version 03
ACTIVITY 2: PLOTTING A HISTOGRAM
Inthe same manner that you plotted a line
graph using an equation, plot find a
suitable equation and plot it.
© H. Chiname 2021. Version 03
ACTIVITY 2 SOLUTION: PLOTTING A HISTOGRAM
© H. Chiname 2021. Version 03
ACTIVITY 2 SOLUTION: PLOTTING A HISTOGRAM
© H. Chiname 2021. Version 03
ACTIVITY 3: PLOTTING A BAR GRAPH
Plota bar graph showing the accumulated
future values of $1000.00 by year, for the
next 20 years.
© H. Chiname 2021. Version 03
ACTIVITY 3 SOLUTION: PLOTTING A BAR GRAPH
© H. Chiname 2021. Version 03
ACTIVITY 3 SOLUTION: PLOTTING A BAR GRAPH
© H. Chiname 2021. Version 03
ACTIVITY 4: A SCATTER PLOT
Makeuse of the random function to
produce random data, and use the data to
create a scatter plot.
© H. Chiname 2021. Version 03
ACTIVITY 4 SOLUTION:
A SCATTER PLOT
© H. Chiname 2021. Version 03
ACTIVITY 4 SOLUTION:
A SCATTER PLOT
© H. Chiname 2021. Version 03
ACTIVITY 5: 3-DIMENSIONAL PLOTTING
Find
a suitable equation and plot a three-
dimensional graph using the output.
© H. Chiname 2021. Version 03
ACTIVITY 5 SOLUTION: 3-DIMENSIONAL PLOTTING
© H. Chiname 2021. Version 03
ACTIVITY 5 SOLUTION: 3-DIMENSIONAL PLOTTING
© H. Chiname 2021. Version 03
OTHER PLOTTING CAPABILITIES PYTHON MODULES
Infact, these Python modules (Matplotlib
and Pyplot) are capable of creating
animated plots, some of which may be
demonstrated in class.
These animated plots are purely for
demonstration purposes and are not
examinable in this course.
© H. Chiname 2021. Version 03
EXERCISES
© H. Chiname 2021. Version 03
EXERCISE 1
Create code for a program that plots a graph
showing the accumulated future values by
year, depending on the data fed into the
program by the user.
The program should ask the user to input the
following values:
The present value;
The interest rate; and
the number of years.
© H. Chiname 2021. Version 03