Lecture 8: Python Writing Scripts in GIS

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Expressions, variables, and for loops (oh my!) spam, spam, spam, spam
Week 4 Strings, if/else, return, user input Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Week 4 gur zntvp jbeqf ner fdhrnzvfu bffvsentr Strings, if/else, return, user input Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their.
Strings, if/else, return, user input
Week 2 ______ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Introduction to Python
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Munster Programming Training
Python Lesson Week 01. What we will accomplish today Install Python on your computer Using IDLE interactively to explore String Variables if/else while.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Unit 2 Expressions and variables; for loops Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Unit 1 Basic Python programs, functions Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
1/10/2008. >>> About Us Paul Beck * Third quarter TA * Computer Engineering * Ryan Tucker * Second quarter TA * Computer.
If/else, return, user input, strings
Strings, if/else, user input
8/2/07. >>> About Me Scott Shawcroft * Junior * Computer Engineering * Third Quarter TA * Creative Commons Intern * Small-time Open Source Developer
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
PHP using MySQL Database for Web Development (part II)
strings, if/else, user input
CompSci 230 S Programming Techniques
Information and Computer Sciences University of Hawaii, Manoa
Fundamentals of Programming I Overview of Programming
C++ First Steps.
Development Environment
Chapter Topics The Basics of a C++ Program Data Types
A Python Tour: Just a Brief Introduction
Introduction to Python
Basic Elements of C++.
Variables, Expressions, and IO
basic Python programs, defining functions
Engineering Innovation Center
CSc 110, Spring 2017 Lecture 8: input; if/else
PH2150 Scientific Computing Skills
review; file processing
Week 1 Review Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted, this work is.
Week 4 gur zntvp jbeqf ner fdhrnzvfu bffvsentr
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Introduction to Python
basic Python programs, defining functions
Python plotting curves chapter 10_5
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
expressions, variables, for loops
Matplotlib.
expressions, variables, for loops
while loops; logic; random numbers; tuples
Introduction to Programming with Python
Suggested self-checks:
COMPUTER PROGRAMMING SKILLS
Unit 3: Variables in Java
Introduction to Python
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Lecture 8: Python Writing Scripts in GIS Dr. Taysir Hassan Abdel Hamid Associate Professor, Information Systems Dept., Faculty of Computers and Information Assiut University April 10, 2016 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Outline The following free online books might be helpful: Think Python Dive Into Python Python Scientific Lecture Notes Google's Python Class INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Outline Module 1: Basic Python programs, functions Module 2: expressions, variables, for loops Module 3: File processing Module 4: Geprocessing with python INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Open source general-purpose language. Object Oriented, Procedural, Functional Easy to interface with C/Java Downloads: http://www.python.org Documentation: http://www.python.org/doc/ INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Python interpreter evaluates inputs: >>> 3*(7+2) 27 • To exit Python: • CTRL-D INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman

Module 1: Python! basic Python programs, defining functions Created in 1991 by Guido van Rossum (now at Google) Named for Monty Python Useful as a scripting language script: A small program meant for one-time use Targeted towards small to medium sized projects Used by: Google, Yahoo!, Youtube Many Linux distributions Games and apps (e.g. Eve Online) Writing GIS Scripts INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman What is a script? INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Who uses Python? “Python is fast enough for our site and allows us to produce maintainable features in record times, with a minimum of developers” -Cuong Do, Software Architect, YouTube.com INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Installing Python Windows: Download Python from http://www.python.org Install Python. Run Idle from the Start Menu. Mac OS X: Python is already installed. Open a terminal and run python or run Idle from Finder. Linux: Chances are you already have Python installed. To check, run python from the terminal. If not, install from your distribution's package system. Note: For step by step installation instructions, see the course web site. INF424: GIS. Dr. Taysir Hassan A. Soliman

The Python Interpreter Allows you to type commands one-at-a-time and see results A great way to explore Python's syntax Repeat previous command: Alt+P INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Console output: System.out.println Methods: public static void name() { ... Hello2.java 1 2 3 4 5 6 7 8 9 public class Hello2 { public static void main(String[] args) { hello(); } public static void hello() { System.out.println("Hello, world!"); INF424: GIS. Dr. Taysir Hassan A. Soliman

Our First Python Program Python does not have a main method like Java The program's main code is just written directly in the file Python statements do not end with semicolons hello.py 1 print("Hello, world!”) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman A Brief Review INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman The print Statement print("text”) print() (a blank line) Escape sequences such as \" are the same as in Java Strings can also start/end with ' swallows.py 1 2 3 4 print(”Hello, world!”) print() print("Suppose two swallows \"carry\" it together.”) print('African or "European" swallows?’) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Comments Syntax: # comment text (one line) swallows2.py 1 2 3 4 5 6 # Suzy Student, CSE 142, Fall 2097 # This program prints important messages. print("Hello, world!”) print() # blank line print(”Suppose two swallows \"carry\" it together.”) print('African or "European" swallows?’) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Functions Function: Equivalent to a static method in Java. Syntax: def name(): statement ... Must be declared above the 'main' code Statements inside the function must be indented hello2.py 1 2 3 4 5 6 7 # Prints a helpful message. def hello(): print("Hello, world!”) # main (calls hello twice) hello() INF424: GIS. Dr. Taysir Hassan A. Soliman

Whitespace Significance Python uses indentation to indicate blocks, instead of {} Makes the code simpler and more readable In Java, indenting is optional. In Python, you must indent. hello3.py 1 2 3 4 5 6 7 8 # Prints a helpful message. def hello(): print("Hello, world!”) print("How are you?”) # main (calls hello twice) hello() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Exercise Rewrite the Figures lecture program in Python. Its output: ______ / \ / \ \ / \______/ +--------+ | STOP | INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Exercise Solution def egg(): top() bottom() print def cup(): line() def stop(): print("| STOP |”) def hat(): def top(): print(" ______”) print(" / \\”) print("/ \\”) def bottom(): print("\\ /”) print(" \\______/”) def line(): print("+--------+”) # main egg() cup() stop() hat() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Module 2 expressions, variables, for loops INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Expressions Arithmetic is very similar to Java Operators: + - * / % (plus ** for exponentiation) Precedence: () before ** before * / % before + - Integers vs. real numbers You may use // for integer division >>> 1 + 1 2 >>> 1 + 3 * 4 - 2 11 >>> 7 // 2 3 >>> 7 / 2 3.5 >>> 7.0 / 2 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Variables Declaring no type is written; same syntax as assignment Operators no ++ or -- operators (must manually adjust by 1) Java Python int x = 2; x++; System.out.println(x); x = x * 8; double d = 3.2; d = d / 2; System.out.println(d); x = 2 x = x + 1 print(x) x = x * 8 d = 3.2 d = d / 2 print(d) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Naming Rules Names are case sensitive and cannot start with a number. They can contain letters, numbers m and underscores: Bob Bob _bob _2bob_ bob_2 BoB There are some reserved words: And, def, class INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Types Python is looser about types than Java Variables' types do not need to be declared Variables can change types as a program is running Value Java type Python type 42 int 3.14 double float "ni!" String str INF424: GIS. Dr. Taysir Hassan A. Soliman

String Multiplication Python strings can be multiplied by an integer. The result is many copies of the string concatenated together. >>> "hello" * 3 "hellohellohello" >>> print(10 * "yo ”) yo yo yo yo yo yo yo yo yo yo INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman >>fruit = “banana” >> letter = fruit[1] >> Print(letter) >> a INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Control Structures INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman The for Loop for name in range(max): statements Repeats for values 0 (inclusive) to max (exclusive) >>> for i in range(5): ... print(i) 1 2 3 4 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman for Loop Variations for name in range(min, max): statements for name in range(min, max, step): Can specify a minimum other than 0, and a step other than 1 >>> for i in range(2, 6): ... print(i) 2 3 4 5 >>> for i in range(15, 0, -5): 15 10 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Nested Loops Nested loops are often replaced by string * and + ....1 ...2 ..3 .4 5 Java 1 2 3 4 5 6 for (int line = 1; line <= 5; line++) { for (int j = 1; j <= (5 - line); j++) { System.out.print("."); } System.out.println(line); Python 1 2 for line in range(1, 6): print((5 - line) * "." + str(line)) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Constants Python doesn't really have constants. Instead, declare a variable at the top of your code. All methods will be able to use this "constant" value. constant.py 1 2 3 4 5 6 7 8 9 10 11 12 13 MAX_VALUE = 3 def printTop(): for i in range(MAX_VALUE): for j in range(i): print(j) print() def printBottom(): for i in range(MAX_VALUE, 0, -1): for j in range(i, 0, -1): print(MAX_VALUE) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Exercise Rewrite the Mirror lecture program in Python. Its output: #================# | <><> | | <>....<> | | <>........<> | |<>............<>| Make the mirror resizable by using a "constant." INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Exercise INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Exercise Solution SIZE = 4 def bar(): print("#" + 4 * SIZE * "=" + "#“) def top(): for line in range(1, SIZE + 1): # split a long line by ending it with \ print("|" + (-2 * line + 2 * SIZE) * " " + \ "<>" + (4 * line - 4) * "." + "<>" + \ (-2 * line + 2 * SIZE) * " " + "|“) def bottom(): for line in range(SIZE, 0, -1): # main bar() top() bottom() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Concatenating Ranges Ranges can be concatenated with + However, you must use the “list()” command Can be used to loop over a disjoint range of numbers >>> list(range(1, 5)) + list(range(10, 15)) [1, 2, 3, 4, 10, 11, 12, 13, 14] >>> for i in list(range(4)) + list(range(10, 7, -1)): ... print(i) 1 2 3 10 9 8 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Exercise Solution 2 SIZE = 4 def bar(): print "#" + 4 * SIZE * "=" + "#" def mirror(): for line in list(range(1, SIZE + 1)) + list(range(SIZE, 0, -1)): print("|" + (-2 * line + 2 * SIZE) * " " + \ "<>" + (4 * line - 4) * "." + "<>" + \ (-2 * line + 2 * SIZE) * " " + "|“) # main bar() mirror() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Strings index 1 2 3 4 5 6 7 or -8 -7 -6 -5 -4 -3 -2 -1 character P . D i d y Accessing character(s): variable [ index ] variable [ index1:index2 ] index2 is exclusive index1 or index2 can be omitted (end of string) >>> name = "P. Diddy" >>> name[0] 'P' >>> name[7] 'y' >>> name[-1] >>> name[3:6] 'Did' >>> name[3:] 'Diddy' >>> name[:-2] 'P. Did' INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman String Methods Java Python length len(str) startsWith, endsWith startswith, endswith toLowerCase, toUpperCase upper, lower, isupper, islower, capitalize, swapcase indexOf find trim strip >>> name = “Jordan Hiroshi Nakamura" >>> name.upper() 'JORDAN HIROSHI NAKAMURA' >>> name.lower().startswith(“jordan") True >>> len(name) 23 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman for Loops and Strings A for loop can examine each character in a string in order. for name in string: statements >>> for c in "booyah": ... print(c) ... b o y a h INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman input input : Reads a string from the user's keyboard. reads and returns an entire line of input >>> name = input("What's your name? ") What's your name? Omar Abdel Aziz >>> name ‘Omar Abdel Aziz' INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman input for numbers to read a number, cast the result of input to an int Only numbers can be cast as ints! Example: age = int(input("How old are you? ")) print("Your age is", age) print("You have", 65 - age, "years until retirement“) Output: How old are you? 53 Your age is 53 You have 12 years until retirement INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman if if condition: statements Example: gpa = input("What is your GPA? ") if gpa > 2.0: print("Your application is accepted.“) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman if/else if condition: statements elif condition: else: Example: gpa = input("What is your GPA? ") if gpa > 3.5: print("You have qualified for the honor roll.“) elif gpa > 2.0: print("Welcome to Mars University!“) print("Your application is denied.“) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman if ... in if value in sequence: statements The sequence can be a range, string, tuple, or list Examples: x = 3 if x in range(0, 10): print("x is between 0 and 9“) name = input("What is your name? ") name = name.lower() if name[0] in "aeiou": print("Your name starts with a vowel!“) INF424: GIS. Dr. Taysir Hassan A. Soliman 48

Logical Operators Operator Meaning Example Result == equals 1 + 1 == 2 True != does not equal 3.2 != 2.5 < less than 10 < 5 False > greater than 10 > 5 <= less than or equal to 126 <= 100 >= greater than or equal to 5.0 >= 5.0 Operator Example Result and (2 == 3) and (-1 < 5) False or (2 == 3) or (-1 < 5) True not not (2 == 3) INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman while Loops while test: statements >>> n = 91 >>> factor = 2 # find first factor of n >>> while n % factor != 0: ... factor += 1 ... >>> factor 7 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman while / else while test: statements else: Executes the else part if the loop does not enter There is also a similar for / else statement >>> n = 91 >>> while n % 2 == 1: ... n += 1 ... else: ... print n, "was even; no loop." ... 92 was even; no loop. INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Random Numbers from random import * randint(min, max) returns a random integer in range [min, max] inclusive choice(sequence) returns a randomly chosen value from the given sequence the sequence can be a range, a string, ... >>> from random import * >>> randint(1, 5) 2 5 >>> choice(range(4, 20, 2)) 16 >>> choice("hello") 'e' INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Pass pass is a special keyword in Python that does nothing. It can be used to fill a control block or a function or a class definition. >> while True: # Do something pass INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Importing import sys a = sys.maxint print a b = a*2 print b INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Lists a = [1, 2, 3] a = [1, 'a', [2, 'b']] a = [1, 2, 3] print a[0] print a[0:1] print a[-1] INF424: GIS. Dr. Taysir Hassan A. Soliman

GeoProcessing with Python 1. Every script using Arc functions must start with import arcpy import arcpy 2. Get user inputs with ‘GetParameterAsText’ 1 2 3 4 5 6 '''script.py ''' import arcpy   # get input feature class inputFeatureClass = arcpy.GetParameterAsText(0) This gets the first user entered parameter as text. INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman Matplotlib.pyplot matplotlib.pyplot is a collection of command style functions that make matplotlib work like MATLAB. Each pyplot function makes some change to a figure: creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc. In matplotlib.pyplot various states are preserved across function calls, so that it keeps track of things like the current figure and plotting area, and the plotting functions are directed to the current axes (please note that “axes” here and in most places in the documentation refers to the axes part of a figure and not the strict mathematical term for more than one axis). INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman For every x, y pair of arguments, there is an optional third argument which is the format string that indicates the color and line type of the plot. The letters and symbols of the format string are from MATLAB, and you concatenate a color string with a line style string. The default format string is ‘b-‘, which is a solid blue line. For example, to plot the above with red circles, you would issue INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman import matplotlib.pyplot as plt plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) plt.show() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman You can add text() The text() command can be used to add text in an arbitrary location, and the xlabel(), ylabel() and title() are used to add text in the indicated locations INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman import numpy as np import matplotlib.pyplot as plt mu, sigma = 100, 15 x = mu + sigma * np.random.randn(10000) # the histogram of the data n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75) plt.xlabel('Smarts') plt.ylabel('Probability') plt.title('Histogram of IQ') plt.text(60, .025, r'$\mu=100,\ \sigma=15$') plt.axis([40, 160, 0, 0.03]) plt.grid(True) plt.show() INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman References http://pro.arcgis.com/en/pro-app/tool-reference/analysis/clip.htm http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/using-functions-in-python.htm https://www.e-education.psu.edu/geog485/node/162 http://resources.arcgis.com/en/help/main/10.2/index.html#//002z00000008000000 INF424: GIS. Dr. Taysir Hassan A. Soliman

INF424: GIS. Dr. Taysir Hassan A. Soliman End of Lecture INF424: GIS. Dr. Taysir Hassan A. Soliman