0

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

6
  • 1
    Your second code is not even valid python. Please create a minimal reproducible example of the issue. Also explain what is wrong with the output more clearly. What is the blue data and the red data and why would you expect them to be equal? Commented Oct 14, 2017 at 14:37
  • @ImportanceOfBeingErnest now it should be Commented Oct 14, 2017 at 14:39
  • 1
    No it is not. If you're having a problem, you need to make it reproducible for others. If minimal reproducible example is not understandable to you, maybe SSCCE will help. Commented Oct 14, 2017 at 14:46
  • 1
    now it should be as it should be... Commented Oct 14, 2017 at 15:04
  • 1
    Copy your code, try to run it: It will not work. The explanation of the problem is also still the same: not clear. I'm giving up on this now. Commented Oct 14, 2017 at 16:25

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.