Reputation: 1523
How to connect every 10th point?
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
#points = np.fromfile('test_acc_history.txt')
points = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0])
plt.figure(100)
plt.plot(points)
plt.show()
The output results in:
BUT, I wanna have a result which should look like a curve:
Upvotes: 0
Views: 552
Reputation: 339052
In order to plot every n
th point, you can slice the array, points[::n]
. To then make sure to have them plotted at the correct position, you also need to supply a list of x values, which is every n
th point from the integer number range.
import numpy as np
import matplotlib.pyplot as plt
points = np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.7, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0])
plt.plot(points)
plt.plot(range(len(points))[::10],points[::10] )
plt.show()
Upvotes: 1