diff options
Diffstat (limited to 'python-graphics/plotter.py')
| -rw-r--r-- | python-graphics/plotter.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/python-graphics/plotter.py b/python-graphics/plotter.py new file mode 100644 index 0000000..b2bc029 --- /dev/null +++ b/python-graphics/plotter.py @@ -0,0 +1,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() |