0% found this document useful (0 votes)
7 views21 pages

4h - Plotting Without Data Using Python Modules

The document discusses plotting in Python without using actual data, utilizing modules like Pyplot and Numpy for creating various types of graphs such as line graphs, histograms, bar graphs, scatter plots, and 3D plots. It includes activities and solutions for plotting different equations and data visualizations. Additionally, it mentions the capability of creating animated plots for demonstration purposes, along with an exercise for users to create a program that plots accumulated future values based on user input.

Uploaded by

mlambofriedrich
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)
7 views21 pages

4h - Plotting Without Data Using Python Modules

The document discusses plotting in Python without using actual data, utilizing modules like Pyplot and Numpy for creating various types of graphs such as line graphs, histograms, bar graphs, scatter plots, and 3D plots. It includes activities and solutions for plotting different equations and data visualizations. Additionally, it mentions the capability of creating animated plots for demonstration purposes, along with an exercise for users to create a program that plots accumulated future values based on user input.

Uploaded by

mlambofriedrich
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

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

You might also like