j35t3r
j35t3r

Reputation: 1523

matplotlib plot in a loop

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:

enter image description here

BUT, I wanna have a result which should look like a curve:

enter image description here

Upvotes: 0

Views: 552

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339052

In order to plot every nth 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 nth 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()

enter image description here

Upvotes: 1

Related Questions