File size: 1,412 Bytes
7b7b8ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ab667f
7b7b8ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4bd99f3
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
import matplotlib
import base64
from io import BytesIO


matplotlib.use('Agg')

import matplotlib.pyplot as plt
class LinearGraphPlotter:
    def __init__(self, x_labels, y_labels):
        self.x_labels = x_labels
        self.y_labels = y_labels

    def plot(self):
        fig, ax = plt.subplots()

        plot_background = "#0D1017"
        outer_background = "#0B0B0B"
        ticks_color = "#fff"
        axvline_color = "#fff"
        points_color = "#fff"
        title_color = "#fff"
        ax.plot(self.x_labels, self.y_labels , color="#ff0000", linewidth=2, marker="o", markerfacecolor="orange", markeredgecolor='orange')


        for i in range(len(self.x_labels)):
            plt.text(self.x_labels[i], self.y_labels[i], f"({round(self.x_labels[i], 2)}, {round(self.y_labels[i], 2)})", color=points_color)


        ax.axvline(0, color=axvline_color)
        ax.axhline(0, color=axvline_color)
        


        plt.grid(True, color="gray", linestyle=":", linewidth=1)

        plt.title("Graph for your equation", color=title_color)
        ax.set_facecolor(plot_background)
        fig.patch.set_facecolor(outer_background)
        plt.xticks(color=ticks_color)
        plt.yticks(color=ticks_color)

        buf = BytesIO()
        plt.savefig(buf, format='png')
        plt.close(fig)

        buf.seek(0)

        graph = base64.b64encode(buf.read()).decode('utf-8')

        return graph