Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views

Fundamentals of Graphical Visualization With Python Programming

This document provides an introduction to graphical visualization using the Python programming language. It describes the Cartesian coordinate system and how to plot points in 2D space. It explains how to represent point coordinates as lists in Python and use matplotlib to plot the points. It demonstrates a Python program that plots multiple points by importing pyplot, creating lists for the x and y coordinates, and using scatter and plot methods. The document also discusses options for running Python programs, including colab.research.google.com.

Uploaded by

Dhuanne Estrada
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Fundamentals of Graphical Visualization With Python Programming

This document provides an introduction to graphical visualization using the Python programming language. It describes the Cartesian coordinate system and how to plot points in 2D space. It explains how to represent point coordinates as lists in Python and use matplotlib to plot the points. It demonstrates a Python program that plots multiple points by importing pyplot, creating lists for the x and y coordinates, and using scatter and plot methods. The document also discusses options for running Python programs, including colab.research.google.com.

Uploaded by

Dhuanne Estrada
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Fundamentals of

Graphical Visualization
with Python Programming
Module 1- Part 1

CS 132 - Mathematics for Computer Science


Learning Objectives

• Describe the Cartesian Coordinate System

• Create a Program for Plotting Points in the Cartesian


Coordinate using Python Programming Language

• Use colab.research.google.com to run a program in Python


!

The Cartesian Coordinate System


Quadrant II Quadrant I

Quadrant IV
Quadrant III

The Cartesian Coordinate System


!

Point in the Cartesian Coordinate System


X

Abscissa of a Point
Y

Ordinate of a point
X -> Abscissa
(X,Y)
Y -> Ordinate

Coordinates of a Point in the Cartesian plane


X (7,5) X=7, Y=5
Y

Point in the Cartesian Coordinate System


-3
7 (7,-3)

Point in the Cartesian Coordinate System


(x2,y2)

(x1,y1)

Two Points Plotted in the Cartesian Plane


(x2,y2)

(x1,y1)

x1=5, y2=5. Hence, (5,5)

x2=-6, y2=8. Hence, (-6,8)

Two Points Plotted in the Cartesian Plane


Should you become a

• Data Analyst
• Data Scientist
You will use an application software or a programming
language to aid your task of plotting points.
“Data Analysts/Scientists”
are using the Python
programming language
“A platform for plotting points that you must know.”
1. Make a list for the abscissas
2. Make a list for the ordinates
Representing Coordinates in Python
Suppose you want to plot the points (1,2)
and (3,9)

1. Make a list for the abscissas, x=[1,3]


2. Make a list for the ordinates, y=[2,9]
Representing Coordinates in Python
Suppose you want to plot the points (1,2) and (3,9). You may use the
“scatter” and “plot” methods of the “pyplot class” in the “matplotlib library”
of Python.

1. Import pyplot from matplotlib ( syntax should be followed ).


2. Make a list for the abscissas, x=[1,3]
3. Make a list for the ordinates, y=[2,9]
4. Pass the lists (x and y) as parameters to the scatter method of matplotlib

Python Program for plotting points


To plot the points (1,2) and (3,9), you may use the
“scatter” and “plot” methods of the “pyplot class” in the
“matplotlib library” of Python.
# The hashtag is the single line comment delimiter in Python.
# Python has a code library called matplotlib
# from which a program for plotting called pyplot may be accessed.
from matplotlib import pyplot as plt # A syntax for import
x=[1,3] # This is the syntax for creating a list of values
y=[2,9]
plt.scatter(x,y, color=“blue”) # Plot the points

Python Program for plotting points


• Command Line-Based
• Integrated Development Environment
• PyCharm
• Spyder ( can be c/o ANACONDA)
• Jupiter Notebook (can be c/o ANACONDA)
• Online Compiler
• colab.research.google.com
Python Programming Platforms
1. Use your gmail to login to mail.google.com
2. Once logged-in, change URL to colab.research.goole.com
3. Be guided by the user-friendly interface. Choose new Notebook and you will be led to an
interface where you can type your program
- Click on the + code button
- Type your code/program in the “textbox area” following a button labeled by a “circle that
contains an arrowhead”.
- Run your program by clicking on the “circle that contains an arrowhead”
- If there are errors in the program, error messages will be displayed. Otherwise, the
output will be shown.

Creating and Executing a Program using Python through

colab.research.google.com

!
Python Programming Interface

colab.research.google.com
To plot the points (1,2) and (3,9), use the “scatter” and
“plot” methods of the “pyplot class” in the “matplotlib
library” of Python.
# This is the single line comment delimiter in Python.
# Python has a code library called matplotlib
# from which a program for plotting called pyplot may be accessed.
from matplotlib import pyplot as plt # A syntax for import
x=[1,3] # This is the syntax for creating a list of values
y=[2,9]
plt.scatter(x,y, color=“blue”) # Plot the points
plt.plot(x,y, color=“red”) # Let a curve pass through the points

Python Program for plotting points


Use the “plot method” in order to let the points be connected by a line/curve
!
Use the “plot method” in order to let the points be connected by a line/curve .
Graphical visualization is for many points
Plotting more than two points
• Several points may easily be plotted.
i.e. (1,1), (2,4),(3,9),(4,16),(5,25),(6,36),(7,49)

Plotting more than two points


• A list of corresponding abscissas and
ordinates .
i.e. (1,1), (2,4),(3,9),(4,16),(5,25),(6,36),(7,49)
x=[1,2,3,4,5,6,7]
y=[1,4,9,16,36,49]
Plotting more than two points
from matplotlib import pyplot as plt # another way of making an import
x=[1,2,3,4,5]
y=[189,256,280,270,286]
plt.plot(x,y, color=“red”) #color parameter sets the color of the curve
plt.scatter(x,y,color=“blue”) # scatter shows the points (i.e scatter diagram)
plt.title(“Curve Passing through Given Points”);
plt.ylabel(“Day of the month”) # label the y-axis
plt.xlabel(“Number of visitors”) # label the x-axis

Example of a Program in Python for Plotting more


than two points
!
Example of a Program in Python for Plotting more
than two points
Required exercise
Do Exercise 1A
(On Philippine Population)
Exercise
Thank You!
Best Regards!
Sincerely yours,

Dalos “Dale” D. Miguel

Course Facilitator

Saint Louis University

30

You might also like