Python Forum
plotting inside the loop is not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
plotting inside the loop is not working
#1
Dear all,
I have this loop and it appears that it does not plot anything when I do that. When I take it outside of the loop, it works just fine. What gives? Thank you!
import time
dims = (40,40)
for i in range (0,81):
    num = int(tmp[i][0])+1
    print(num)
    mymap = read_corp('mydata'+str(num)+'.txt')
    mymap = mymap.reshape(dims[0],dims[1])
    xi=4
    yi=3
    plt.imshow(mymap)
    plt.plot(xi,yi, marker='X')

    xi=20
    yi=3
    plt.imshow(mymap)
    plt.plot(xi,yi, marker='*')
    time.sleep(10)
    plt.close()
Reply
#2
This code should return NameError as name 'tmp' on row 4 is not defined.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Hi, I do have tmp defined in one of my functions:)
Reply
#4
But it's not in the code snippet you posted.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
(Apr-10-2019, 01:37 PM)jenya56 Wrote: Hi, I do have tmp defined in one of my functions:)

So you withheld essential information about your code but still expect that somebody is able to help you? This behaviour reduces significantly ability and willingness of participants of this forum to help you.

And if your information is true (i.e. you have assigned name in one of functions) then you should get NameError anyway. Namespace within function is not accessible from outside of function (with some subtlety regarding global and closure)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 375 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,526 Nov-07-2023, 09:49 AM
Last Post: buran
  while loop not working-I am using sublime text editor mma_python 4 1,060 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  Help adding a loop inside a loop Extra 31 4,340 Oct-23-2022, 12:16 AM
Last Post: Extra
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,434 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Adding to the dictionary inside the for-loop - weird behaviour InputOutput007 5 2,651 Jan-21-2021, 02:21 PM
Last Post: InputOutput007
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 2,467 Jan-10-2021, 01:50 AM
Last Post: JulyFire
  Creating a variables inside FOR loop zazas321 5 4,040 Sep-16-2020, 04:42 PM
Last Post: Naheed
  Why is the while loop not working? mcoliver88 5 3,044 Aug-18-2020, 03:27 PM
Last Post: deanhystad
  Infinite loop not working pmp2 2 1,609 Aug-18-2020, 12:27 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020