From 776bfddd0827db0efe646eed7840df79c00e2f65 Mon Sep 17 00:00:00 2001 From: Louis Date: Mon, 19 Jun 2023 09:04:21 +0200 Subject: [PATCH] script for generating graphs (cities) --- .../generate_cities_with_matplotlib.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/data_sample/generate_cities_with_matplotlib.py diff --git a/tests/data_sample/generate_cities_with_matplotlib.py b/tests/data_sample/generate_cities_with_matplotlib.py new file mode 100644 index 0000000..b711ccf --- /dev/null +++ b/tests/data_sample/generate_cities_with_matplotlib.py @@ -0,0 +1,33 @@ +import matplotlib.pyplot as plt + +# Liste pour stocker les coordonnées des points cliqués +points = [] + +def onclick(event): + global points + # Ajouter le point cliqué à la liste + points.append([int(event.xdata), int(event.ydata)]) + + # Afficher le point sur le graphique + plt.plot(event.xdata, event.ydata, 'ro') + + plt.draw() # Redessiner le graphique + +# Créer un graphique vierge de 1000 par 1000 +fig, ax = plt.subplots(figsize=(10,10)) +plt.xlim(0, 1000) +plt.ylim(0, 1000) + +# Connecter le gestionnaire d'événements au graphique +cid = fig.canvas.mpl_connect('button_press_event', onclick) + +plt.show() + +# Afficher les points cliqués +for point in points: + print(f"Ville à la position {point}") + +# Si vous voulez avoir les positions dans une liste, vous pouvez le faire comme suit +print(points) + +input() \ No newline at end of file