'Plot points after certain interval using matplotlib

I have 2 arrays, array_x and array_y.

  • array_x = [1, 2, 3, 4, 5, 6, 7, …]
  • array_y = [1132.4, 1128.7, 1148, 1171.55, 1193.85, 1198.5, 1219.65, …]

I am trying to plot data using matplotlib.

plt.plot(array_x, array_y, color = "blue")

But I am getting plot too compact

enter image description here

How can I plot graph using every 3rd entry of array_x and array_y to plot the graph like array_x = [3, 6, …], array_y = [1148, 1198.5, …] so that graph would look much better for analysis?



Solution 1:[1]

I see K.Cl answered it in the comments above. But I wanted to play with it and make it where you can try a different entry simply by changing one variable.

entry = 3 # use every 3rd entry
plt.plot(array_x[entry-1::entry], array_y[entry-1::entry], color = "blue")

Below is the code I was playing with:

array_x = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]

entry = 3  

print(array_x[entry-1::entry])  # start at 3rd and step every 3
print(array_x[0::entry])        # start at 1st spot and step every 3
print(array_x)                  # list is still intact.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TomasO