0

I have a some x and y coordinates like this:

x = [None, 5, 7, None, None, 9]
y = [1, 2, 3, 4, 5, 6]

I want a while loop to go through each list item in turn and plot a circle marker if it has an x and y coordinate and then the plot must stay there as it continues to plot more values, eventually it will have plotted every value from the lists.

Code:

i = 0
while i < 100:
    plt.plot((b[i]), (a[i]), marker='o')
    plt.ion()
    plt.pause(1)
    i += 1

Some reason, it seems to plot the marker and then it disappears, any ideas?

2
  • Do you want it to pause after each dot? You could simply feed it the list of elements preprocessed. Commented Jan 24, 2017 at 12:44
  • It's suppose to replicate data that is on a 1 second interval, so it needs to be shown with the pause. Commented Jan 24, 2017 at 12:47

1 Answer 1

4

You question gives lists x and y and then uses a and b in the loop, so I'll just make something up for a and b and assume you have the filtering out of None's working.

a = [1, 5, 7, 1, 1, 9]
b = [1, 2, 3, 4, 5, 6]

You just need to set interactive once - not over and over in the loop. But this isn't the cause of the problem - just saying

plt.ion()

for (x, y) in zip(a,b):
    plt.plot(x, y, marker = 'o')
    plt.pause(1)

What I observe is that the points are showing up - but the scale changes to show the new point - others are off the screen. If I zoom out enough all the points are actually there.

You may wish to give some thought to your axes scale; something like

plt.xlim([min(a)-1, max(a)+1])
plt.ylim([min(b)-1, max(b)+1])

should make all your data fit on the same plot without points seeming to disappear

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.