I'm trying to plot a voronoi diagram with real time data, but get the error:
IndexError: tuple index out of range
the code:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
data = str(data, "utf-8") #convert bytes into string and fix the 'b'
#data.decode("utf-8", errors="ignore")
data = data.strip(" ").split(".")
x = data[0]
y = data[1]
x = float(x.replace( ',', '.'))
y = float(y.replace( ',', '.'))
vor = Voronoi(x,y)
The value of the data
variable is like this: [b' 0,2036377.2,04291.', b' 0,2027879.2,040747.']
.
Any idea how to fix this?
As mentioned in the comments, the error you are getting is because you are passing the wrong input to
Voronoi
, please read the documentationRegarding what you are trying to do and assuming that the
data
you get fromdata, addr = sock.recvfrom(1024)
is like this[b' 0,2036377.2,04291.', b' 0,2027879.2,040747.']
you then have to do address the following points:float
Voronoi
diagramThe code you have so far address most of these points but it does not structure the data as the input for the
Voronoi
diagram.The code bellow addressed all the points and will create the
Voronoi
diagram for you:The result is the following: