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