From 430a599dcd9454f95c85ab6eb6b72eb15d584b92 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Mon, 5 Apr 2021 19:52:58 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=D1=8C=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B8=20=D0=BF=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=87=D0=B5=D1=87=D0=BD=D1=8B=D0=B5=20=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D1=84=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python-graphics/plotter.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 python-graphics/plotter.py (limited to 'python-graphics/plotter.py') 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() -- cgit v1.2.3