-
Notifications
You must be signed in to change notification settings - Fork 24
/
math10.py
30 lines (26 loc) · 1018 Bytes
/
math10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from matplotlib import pyplot as plt
import numpy as np
# this library is for plotting in math 10
# adapted from Umut's math9 library
def drawfunction(f, imsize=200):
# a 2 variable funciton surface
arr = np.zeros([imsize,imsize])
for i in range(imsize):
for j in range(imsize):
xx = (i - imsize/2) / imsize * 2
yy = (-j + imsize/2) / imsize * 2
arr[j,i] = f(xx,yy)
fig = plt.figure(figsize=(7, 5))
ax = fig.add_subplot(1,1,1)
ax.tick_params(labelsize=14)
plt.imshow(arr, interpolation='nearest', cmap='gray', aspect = 'equal', vmin=0, vmax=1, extent = [-1,1,-1,1])
plt.show()
def graphfunction(f, precision=300, x1=-1, x2=1, y1=-1, y2=1):
# a one-var funciton
arx = np.fromfunction(lambda i: ((i-precision/2)/precision*2), (precision, ))
ary = np.vectorize(f)(arx)
plt.figure()
plt.axis('auto')
plt.grid(alpha = 0.6, linestyle='dashed')
plt.plot(arx, ary, color = 'black', linewidth=4.0)
plt.show()