I have a scatterplot like the one shown in the figure and I want to connect the points with segments, but not all, but in groups of 5. That is, four segments that join the first 5 points, four segments that join the following 5 points and so on... that's 120 points in total, so that would be 24 groups of 5.
This is the code that generated that chart:
plt.scatter(np.arange(1,121), mos[0:120])
plt.title('Imagen 1')
plt.ylabel('MOS')
plt.xlabel('Numero de Imagen')
plt.grid(True)
plt.tight_layout()
plt.show()
How do I add the segments?
From already thank you very much.
You can do the following:
Keep in mind that I don't have the array
mos
so I simulate it with random values. What defines the segments is the following code:That is, we walk
mos
in steps ofcant = 5
and then we build the 4 segment points, establishing the start and end point:p = [(y[i+j], mos[i+j]), (y[i+j+1], mos[i+j+1])]
. The output would be something like this:You must draw the portions. Instead of using
scatter
you can useplot
to get the effect you want. A code example would be:Possible result: