Uploaded by asraed4

233 Midterm 2 Aid Sheet (2)

advertisement
Property
alpha
antialiased
color
solid_capstyle
solid_joinstyle
data
label
linestyle
Possible property values
float
Boolean
A matplotlib color
'butt', 'round', or 'projecting'
'miter', 'round', or 'bevel'
[x_data, y_data]
string
'-', '--', '-.', ':', ... (see above)
Description
alpha compositing enables transparency
Enabled anti-aliasing of the line
Color of the markers, line
How the cap of a line appears
How the join of a line appears
The arrays of x and y coordinates
The label to use for the line
The style of the line
linewidth
float
The width of the line when drawn.
marker
'+', ',', '.', '1', '2', ... (see above)
The style of the marker to use
markersize
float
The size of the marker
visible
Boolean
Show/hide the line
Character(s)
b
g
r
w
k
y
m
c
--.
:
Line color/style
Blue
Green
Red
White
Black
Yellow
Magenta
Cyan
Solid line
Dashed line
Dashed-dot line
Dotted line
Character(s)
.
,
o
+
X
v
^
<
>
*
p
Marker style
Point marker
Pixel marker
Circle marker
Plus marker
X marker
Triangle-down marker
Triangle-up marker
Triangle-left marker
Triangle-right marker
Star marker
Pentagon marker
Character(s)
1
2
3
4
h
H
D
d
|
_
s
Marker style
Tri-down marker
Tri-up marker
Tri-left marker
Tri-right marker
Hexagon1 marker
Hexagon2 marker
Diamond marker
Thin diamond marker
Vertical line marker
Horizontal line marker
Square marker
The matplotlib package can be used for plotting in Python. matplotlib replicates the plotting capability of MATLAB, an engineeringoriented programming language. matplotlib is short for "MATLAB plotting library." Script: A file containing python code passed as
input to the interpreter
Module: a file containing python code imported by a script, module or the interactive interpreter
Dot notation: used to reference an object in an imported module
Import: executes the contents of a file containing python code and makes the definitions from that file available . Print(all([1,2,3])) =
True
print(any([0,0])) = false
•
•
•
•
•
•
isalnum() -- Returns True if all characters in the string are lowercase or uppercase letters, or the numbers 0-9.
isdigit() -- Returns True if all characters are the numbers 0-9.
islower() -- Returns True if all cased characters are lowercase letters.
isupper() -- Return True if all cased characters are uppercase letters.
isspace() -- Return True if all characters are whitespace.
startswith(x) -- Return True if the string starts with x.
•
endswith(x) -- Return True if the string ends with x
Range(5,0,-1) = 5 4 3 2 1
range(5,0,-2) = 5 3 1 ceil: max pe round
floor:smallest pe round
my_str=’Johnny Depp’ my_str[::2] = ‘Jhn ep’ my_str[2::] = ‘nny Depp’ my_str[0:1] = ‘J’
< left aligned > right aligned ^ centre aligned
1-sys module checked for HTTP server
2-module object created
3-HTTP server added to sys modules
4-HTTP server code executed
5-HTTP server added to importer’s namespace
Built in modules = sys,time,math
Hashlib module: a python standard library module that contains a no. Of algorithms for creating a secure hash of a text msg
A built-in module is a module that comes pre-installed with Python; examples of built-in modules include sys, time, and math. If no
matching built-in module is found, then the interpreter searches the list of directories contained by sys.path, located in the sys
module. Larger projects might contain tens or hundreds of modules or use third-party modules located in different directories. In
such cases, a programmer might set the environment variable PYTHONPATH in the operating system. An operating system
environment variable is much like a variable in a Python script, except that an environment variable is stored by the computer's
operating system and can be accessed by every program running on the computer
n Windows, a user can set the value of PYTHONPATH permanently through the control panel, or temporarily on a single instance of
a command terminal (cmd.exe) using the command set PYTHONPATH="c:\dir1;c:\other\directory".
__name__ is a global string variable automatically added to every module that contains the name of the module. Ex:
my_funcs.__name__ would have the value "my_funcs", and web_search.__name__ would have the value "web_search".
If if __name__ == "__main__" is true, then the file is being executed as a script and the branch is taken. Otherwise, the file was
imported and thus __name__ is equal to the module name, e.g., "web_search".A package is a directory that, when imported, gives
access to all of the modules stored in the directory. Large projects are often organized using packages to group related
modules._init_.py as keyword renames an imported module or package plt.show() fn. Displays the graphDocstring is a string literal
placed placed in the 1st line of a function bodyUse a for loop when the number of iterations is computable before entering the
loopUse a for loop when accessing the elements of a containerUse a while loop when the no. Of iterations is not computableChr()
converts integer to characterOrd() converts string to integerFixme comment attracts attention to code that needs to be fixed in the
futureBreak statement in a loop causes the loop to exit immediatelyContinue statement causes an immediate jump to the while or
for loop
Function
Description
Function
Number representation and theoretic functions
ceil(x)
Round up value
factorial(x)
factorial (3! = 3 * 2 * 1)
fabs(x)
floor(x)
fmod(x, y)
fsum(x)
Remainder of division
Description
Absolute value
Round down value
Floating-point sum of a
range, list, or array.
Power, exponential, and logarithmic functions
exp(x)
Exponential function ex
log(x, (base))
pow(x, y)
Raise x to power y
Trigonometric functions
acos(x)
Arc cosine
sqrt(x)
atan(x)
atan2(y, x)
cos(x)
Arc tangent
Cosine
Length of vector from
hypot(x1, x2, x3, ..., xn)
origin
Convert degrees to
radians(x)
radians
cosh(x)
Hyperbolic cosine
Complex number functions
gamma(x)
Gamma function
Mathematical constants
Mathematical constant
pi (constant)
3.141592...
asin(x)
sin(x)
degrees(x)
Natural logarithm;
base is optional
Square root
Arc sine
Arc tangent with two
parameters
Sine
Convert from radians
to degrees
tan(x)
Tangent
sinh(x)
Hyperbolic sine
erf(x)
Error function
e (constant)
Mathematical constant
2.718281...
Download