Initial commit. completed exercises up to chapter 2. Graphing equations.

master
androiddrew 6 years ago
commit 4e15d8f6f5

63
.gitignore vendored

@ -0,0 +1,63 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Pycharm
.idea

@ -0,0 +1,38 @@
"""
Simple example demonstrating graphing with functions
Topic: Newton's law of Universal Gravitation
Models the relationship between gravitational force and distance between two bodies.
"""
import matplotlib.pyplot as plt
G = 6.674 * (10 ** -11)
def draw_graph(x, y):
plt.plot(x, y, marker="o")
plt.xlabel("Distance in Meters")
plt.ylabel("Gravitational Force in Newtons")
plt.title("Gravitational Force and Distance")
plt.show()
def generate_F_r():
"""Generates values for r in the New"""
r = range(100, 1001, 50)
F = []
m1 = 0.5
m2 = 1.5
for dist in r:
force = G * (m1 / m2) / (dist ** 2)
F.append(force)
draw_graph(r, F)
if __name__ == "__main__":
generate_F_r()

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -0,0 +1,19 @@
"""
Simple Pyplot example
PyPlot is the module you should be using for non-interactive scripts.
"""
import matplotlib.pyplot
def create_graph():
x_nums = [1, 2, 3]
y_nums = [2, 4, 6]
matplotlib.pyplot.plot(x_nums, y_nums)
matplotlib.pyplot.show()
if __name__ == "__main__":
create_graph()

@ -0,0 +1,19 @@
"""
Example saving a figure
"""
import matplotlib.pyplot as plt
import pathlib
HERE = pathlib.Path(__file__).parent
def create_graph():
x = [1, 2, 3]
y = [2, 4, 6]
plt.plot(x, y)
plt.savefig(HERE.joinpath("mygraph.png"))
if __name__ == "__main__":
print(HERE)
create_graph()

@ -0,0 +1,17 @@
"""
Simple pylab example
Use pylab when you are in an interactive shell. This example really should be copied into a RPEL.
"""
from pylab import plot, show
x_numbers = [1, 2, 3]
y_numbers = [2, 4, 6]
my_graph = plot(x_numbers, y_numbers, marker='o')
# my_graph = plot(x_numbers, y_numbers, 'o')
if __name__ == "__main__":
show()

@ -0,0 +1,20 @@
from pylab import legend, plot, show, title, xlabel, ylabel, axis
nyc_temp_2000 = [31.3, 37.3, 47.2, 51.0, 63.5, 71.3, 72.3, 72.7, 66.0, 57.0, 45.3, 31.1]
nyc_temp_2006 = [40.9, 35.7, 43.1, 55.7, 63.1, 71.0, 77.9, 75.8, 66.6, 56.2, 51.9, 43.6]
nyc_temp_2012 = [37.3, 40.9, 50.9, 54.8, 65.1, 71.0, 78.8, 76.7, 68.8, 58.0, 43.9, 41.5]
months = range(1, 13)
plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
title('Average monthly temperature in NYC')
xlabel("Month")
ylabel("Temperature")
legend([2000, 2006, 2012])
axis(ymin=0)
show()

@ -0,0 +1,13 @@
from pylab import legend, plot, show
nyc_temp_2000 = [31.3, 37.3, 47.2, 51.0, 63.5, 71.3, 72.3, 72.7, 66.0, 57.0, 45.3, 31.1]
nyc_temp_2006 = [40.9, 35.7, 43.1, 55.7, 63.1, 71.0, 77.9, 75.8, 66.6, 56.2, 51.9, 43.6]
nyc_temp_2012 = [37.3, 40.9, 50.9, 54.8, 65.1, 71.0, 78.8, 76.7, 68.8, 58.0, 43.9, 41.5]
months = range(1, 13)
plot(months, nyc_temp_2000, months, nyc_temp_2006, months, nyc_temp_2012)
legend([2000, 2006, 2012])
show()

@ -0,0 +1,12 @@
from pylab import plot, show
from decimal import Decimal
nyc_temp = [50.9, 60.3, 54.4, 52.4, 51.5, 52.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 57.3]
dec_nyc_temp = list(map(lambda x: Decimal(str(x)), nyc_temp))
years = range(2000, 2013)
plot(years, dec_nyc_temp, marker='o')
show()

@ -0,0 +1,7 @@
from pylab import plot, show
nyc_temp = [53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 57.3]
plot(nyc_temp, marker="o")
show()

@ -0,0 +1 @@
matplotlib
Loading…
Cancel
Save