0

Hi i'm trying to get a set of points from matplotlib.pyplot.ginput. my idea is to save points in a list while the actuaPoint!=lastPoint

is there a way to do it something like:

lastPoint = None
pointList = []

actualPoint = plt.ginput(1)
while (actualPoint=plt.input()) != lastPoint:
    pointList.append(actualPoint)
    lastPoint= actualPoint

? resuming i'm trying to know if there's a way to do the variable assignment inside the while statement

2
  • 1
    Replace = with := in your while statement. Commented Oct 28, 2021 at 20:12
  • Important to mention that := operator works only in python 3.9+ ! Commented Oct 28, 2021 at 20:27

1 Answer 1

1

You need to use an assignment expression, using the := operator.

point, = pointList = [plt.ginput(1)]
while (next_point := plt.input()) != point:
    pointList.append(next_point)
    point = next_point
Sign up to request clarification or add additional context in comments.

2 Comments

This was exactly was I was looking for! many thanks! worked like charm! Also im gonna edit my post i wanted to user plt.ginput not input. If you could modify yours to match would be perfect
That actually makes it a little nicer, as I was struggling to find a cleaner way to avoid the duplicate call to plt.input.

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.