blob: b2bc0297dcc21301321051d7fc7e006e2dfcc14f (
plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import matplotlib.pyplot as plt
import numpy as np
def plot_preset(data):
a = data["a"]
b = data["b"]
min_x = data["min"]
max_x = data["max"]
# 100 linearly spaced numbers
x = np.linspace(min_x, max_x, 100)
if data["type"] == "parabola":
c = data["c"]
y = a * x**2 + b * x + c
elif data["type"] == "line":
y = a * x + b
# setting the axes at the centre
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
# plot the function
plt.plot(x,y, 'r')
# show the plot
plt.show()
def plot_points(data):
points = data["points"]
x = []
y = []
for (xi, yi) in points:
x.append(xi)
y.append(yi)
# setting the axes at the centre
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
# plot the function
plt.plot(x,y, data["mode"])
# show the plot
plt.show()
|