script for generating graphs (cities)
This commit is contained in:
parent
0f5b70bd6f
commit
776bfddd08
33
tests/data_sample/generate_cities_with_matplotlib.py
Normal file
33
tests/data_sample/generate_cities_with_matplotlib.py
Normal file
@ -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()
|
||||
Loading…
x
Reference in New Issue
Block a user