diff --git a/plotGraph.py b/plotGraph.py new file mode 100644 index 00000000..74bb6455 --- /dev/null +++ b/plotGraph.py @@ -0,0 +1,59 @@ +import matplotlib.pyplot as plt +from tkinter import Tk, Entry, Label, Button + +class GraphPlotter: + def __init__(self, master): + self.master = master + master.title("Graph Plotter") + master.geometry("500x400") # Set the dimensions of the window + + # Font size for labels and entries + font_size = 14 + + self.x_coordinates = [] + self.y_coordinates = [] + + self.x_label = Label(master, text="Enter x-coordinate:", font=("Arial", font_size)) + self.x_label.pack() + + self.x_entry = Entry(master, font=("Arial", font_size)) + self.x_entry.pack() + + self.y_label = Label(master, text="Enter y-coordinate:", font=("Arial", font_size)) + self.y_label.pack() + + self.y_entry = Entry(master, font=("Arial", font_size)) + self.y_entry.pack() + + self.plot_button = Button(master, text="Plot", command=self.plot_graph, font=("Arial", font_size)) + self.plot_button.pack() + + self.quit_button = Button(master, text="Quit", command=master.quit, font=("Arial", font_size)) + self.quit_button.pack() + + def plot_graph(self): + x_input = self.x_entry.get() + y_input = self.y_entry.get() + + try: + x_value = float(x_input) + y_value = float(y_input) + self.x_coordinates.append(x_value) + self.y_coordinates.append(y_value) + + self.x_entry.delete(0, 'end') + self.y_entry.delete(0, 'end') + except ValueError: + print("Invalid input. Please enter valid numbers.") + + plt.plot(self.x_coordinates, self.y_coordinates, marker='o') + plt.xlabel('X-axis', fontsize=14) + plt.ylabel('Y-axis', fontsize=14) + plt.title('Graph Plot', fontsize=16) + plt.grid(True) + plt.show() + +if __name__ == '__main__': + root = Tk() + graph_plotter = GraphPlotter(root) + root.mainloop() diff --git a/reversePlotGraph.py b/reversePlotGraph.py new file mode 100644 index 00000000..c23c7854 --- /dev/null +++ b/reversePlotGraph.py @@ -0,0 +1,54 @@ +import pandas as pd +import matplotlib.pyplot as plt +from matplotlib.widgets import Button +import os + +coordinates_df = pd.DataFrame(columns=['x', 'y']) +prev_point = None + +def on_click(event): + global prev_point + + # Check if the click is within the axes + if event.inaxes: + x, y = round(event.xdata), round(event.ydata) + coordinates_df.loc[len(coordinates_df)] = [x, y] + print(f'Clicked at: x = {x}, y = {y}') + + # Plot the clicked point on the graph + ax.plot(x, y, 'ro') # 'ro' for red dots + + # Connect to the previous point + if prev_point: + prev_x, prev_y = prev_point + ax.plot([prev_x, x], [prev_y, y], 'b-') # 'b-' for blue lines + + # Update the plot + plt.draw() + + # Update the previous point + prev_point = (x, y) + +def save_to_excel(event): + if not os.path.exists('output'): + os.makedirs('output') + + file_path = 'output/coordinates.xlsx' + coordinates_df.to_excel(file_path, index=False) + print(f'Coordinates saved to {file_path}') + +# Create a figure and axis +fig, ax = plt.subplots() +ax.set_xlim(0, 10) +ax.set_ylim(0, 10) +ax.set_title('Click on the graph to add coordinates') + +# Register the click event +fig.canvas.mpl_connect('button_press_event', on_click) + +# Create a button to save the coordinates to Excel +ax_button = plt.axes([0.8, 0.01, 0.1, 0.05]) +save_button = Button(ax_button, 'Save to Excel') +save_button.on_clicked(save_to_excel) + +plt.show()