Re: plotting slows down

2014-01-14 Thread Norman Elliott
On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott  wrote:
> First let me say I have not done much python programming!
> 
> I am running Python 2.7.3.
> 
> I am trying to use python as a front end to a simple oscilloscope.
> 
> Ultimately I intend to use it with my micropython board.
> 
> 
> 
> At the moment I am just developing it. All it does is use a module I found 
> called graphics.py to create a window and display randomly generated data.
> 
> 
> 
> Each time it goes through the outer loop it gets slower and slower.
> 
> I put in a small delay just so I could observe what is happening and for the 
> first line it draws it takes about a second. If I set it to loop 20 times the 
> final loop takes more than 6 seconds.
> 
> Can anyone explain what I am doing wrong please?
> 
> Here is the code:
> 
> [code]
> 
> #!/usr/bin/python
> 
> from graphics import *
> 
> import random
> 
> import time
> 
> 
> 
> xpos=1200
> 
> ypos=400
> 
> ypnt=ypos/2
> 
> pos=1
> 
> #setBackground("white")
> 
> def main():
> 
>   win = GraphWin("My Circle", xpos, ypos)
> 
> # win.setBackGround('white')
> 
>   for y in range(1,5):
> 
>   cir2 = Circle(Point(xpos/2,20), 10)
> 
>   cir2.setFill("white")
> 
>   cir2.draw(win)
> 
>   message = Text(Point(win.getWidth()/2, 20), y)
> 
>   message.draw(win)
> 
>   j = random.randint(1,ypos)
> 
>   for x in range(1,xpos):
> 
>   updown = random.randint(0,1)
> 
>   if updown:
> 
>   j=j+1
> 
>   else:
> 
>   j=j-1
> 
>   if j <1:
> 
>   j=ypos/2
> 
>   if j>ypos-1:
> 
>   j=ypos/2
> 
>   win.plot(x,j,"red")
> 
>   time.sleep(.0001)
> 
> 
> 
> main()
> 
> time.sleep(5)
> 
> [/code]

Okay, maybe I misunderstood what it was doing. I have checked and I will do a 
find and replace of the tabs with 4 spaces in future. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread Chris Angelico
On Wed, Jan 15, 2014 at 12:15 AM, Rustom Mody  wrote:
> However it can also mean that gedit sets tabstops at 4 character intervals
> Which will mean you will see 4 characters (in gedit) and everyone else will 
> see a
> tab. This is a recipe for trouble.

Not a recipe for trouble normally, it's just that some people's
clients can't see them. So keep using tabs if you want to, but be
prepared to search-and-replace them to spaces prior to posting code.
Though I think the fault is with the client(s) that can't see tabs,
and they're the ones that ought to be fixed.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread Rustom Mody
On Tuesday, January 14, 2014 6:34:43 PM UTC+5:30, Norman Elliott wrote:
> @Dave, no problem. I am using gedit to write the files and have it set to 
> translate tabs into 4 spaces which is what was recommended to me as the right 
> amount of indenting for python scripts.

Dunno what you mean by 'translate'
If that means actually replace the characters, then that will cause minimum 
problems

However it can also mean that gedit sets tabstops at 4 character intervals
Which will mean you will see 4 characters (in gedit) and everyone else will see 
a 
tab. This is a recipe for trouble.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread Norman Elliott
@Dave, no problem. I am using gedit to write the files and have it set to 
translate tabs into 4 spaces which is what was recommended to me as the right 
amount of indenting for python scripts.

On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott  wrote:
> First let me say I have not done much python programming!
> 
> I am running Python 2.7.3.
> 
> I am trying to use python as a front end to a simple oscilloscope.
> 
> Ultimately I intend to use it with my micropython board.
> 
> 
> 
> At the moment I am just developing it. All it does is use a module I found 
> called graphics.py to create a window and display randomly generated data.
> 
> 
> 
> Each time it goes through the outer loop it gets slower and slower.
> 
> I put in a small delay just so I could observe what is happening and for the 
> first line it draws it takes about a second. If I set it to loop 20 times the 
> final loop takes more than 6 seconds.
> 
> Can anyone explain what I am doing wrong please?
> 
> Here is the code:
> 
> [code]
> 
> #!/usr/bin/python
> 
> from graphics import *
> 
> import random
> 
> import time
> 
> 
> 
> xpos=1200
> 
> ypos=400
> 
> ypnt=ypos/2
> 
> pos=1
> 
> #setBackground("white")
> 
> def main():
> 
>   win = GraphWin("My Circle", xpos, ypos)
> 
> # win.setBackGround('white')
> 
>   for y in range(1,5):
> 
>   cir2 = Circle(Point(xpos/2,20), 10)
> 
>   cir2.setFill("white")
> 
>   cir2.draw(win)
> 
>   message = Text(Point(win.getWidth()/2, 20), y)
> 
>   message.draw(win)
> 
>   j = random.randint(1,ypos)
> 
>   for x in range(1,xpos):
> 
>   updown = random.randint(0,1)
> 
>   if updown:
> 
>   j=j+1
> 
>   else:
> 
>   j=j-1
> 
>   if j <1:
> 
>   j=ypos/2
> 
>   if j>ypos-1:
> 
>   j=ypos/2
> 
>   win.plot(x,j,"red")
> 
>   time.sleep(.0001)
> 
> 
> 
> main()
> 
> time.sleep(5)
> 
> [/code]

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-14 Thread Dave Angel
 Norman Elliott  Wrote in message:
> 
> I cannot see how to change from html to text mode in chromium or within the 
> group.
> 

You already did post in text mode, my error. The new newsreader
 I'm using apparently eats tabs.

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Terry Reedy

On 1/13/2014 12:45 PM, Chris Angelico wrote:

On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly  wrote:

On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel  wrote:

Next, please repost any source code with indentation preserved.
  Your message shows it all flushed to the left margin,  probably
  due to posting in html mode. Use text mode here.


That's odd, the message that I got includes proper indentation and is
plain text, not html.


Also what I saw. Dave, do you get the newsgroup or the mailing list? I
get the mailing list - it's possible the HTML version got stripped by
Mailman.


I am reading via gmane. Viewing the source, there is no html.
BUT, indents are with tabs, not spaces. Some readers just delete tabs, 
as there is no standard for conversion to spaces, especially with 
proportional fonts. Thunderbird used to do this, but now uses tab stops 
every 8 spaces (maybe because a switched to a fixed font?) This means 
that the first tab gives an indent 8 chars in the original post, 6 in 
the first quotation, and, I presume, 4 in a second quotation, etc. It 
works better to post code with space indents.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Norman Elliott
On Monday, 13 January 2014 18:05:52 UTC, Dave Angel  wrote:
> Chris Angelico  Wrote in message:
> 


Well Ian's suggestion has really done the job. Now each iteration takes just 
0.14 seconds now.
changed to:
[code]
win = GraphWin("My Circle", xpos, ypos, autoflush=False)
[/code]

and added 
[code]
update()
[/code]

immediately after the line
[code]
for y in range(1,12):
[/code]

previously the first iteration took 0.48 seconds and the the 10th 4.76
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Ian Kelly
On Mon, Jan 13, 2014 at 1:15 AM,   wrote:
> First let me say I have not done much python programming!
> I am running Python 2.7.3.
> I am trying to use python as a front end to a simple oscilloscope.
> Ultimately I intend to use it with my micropython board.
>
> At the moment I am just developing it. All it does is use a module I found 
> called graphics.py to create a window and display randomly generated data.
>
> Each time it goes through the outer loop it gets slower and slower.
> I put in a small delay just so I could observe what is happening and for the 
> first line it draws it takes about a second. If I set it to loop 20 times the 
> final loop takes more than 6 seconds.
> Can anyone explain what I am doing wrong please?

I wager the problem is in the "range(1, xpos)" inner loop.  Each time
this runs the win.plot() call adds a 1-pixel line to the underlying Tk
canvas.  These 1-pixel lines are never deleted, so they accumulate
over each outer loop.  Every time a new object is drawn, the canvas
has to process all of the lines that have been drawn in order to
redraw itself, and so it gets slower and slower.

One simple fix you might try to improve the rendering efficiency is to
disable the autoflush option documented here:

http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node14.html

And then call the module-level update() function after each iteration
of the outer loop to force things to redraw.  In order to
realistically use this module for animation it looks like you will at
some point need to keep the number of graphics objects under some
constant.  To do this you could either reuse the existing objects by
calling their "move" method to reposition them as needed, or simply
remove them from the plot with the "undraw" method and draw new
objects in their place.  See:

http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node3.html

If this still isn't fast enough for the number of objects you're
drawing, then you may just need to find a new drawing package, as this
one appears to be designed for teaching rather than efficiency.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Dave Angel
 Chris Angelico  Wrote in message:
> On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly  wrote:
>> On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel  wrote:
>>> Next, please repost any source code with indentation preserved.
>>>  Your message shows it all flushed to the left margin,  probably
>>>  due to posting in html mode. Use text mode here.
>>
>> That's odd, the message that I got includes proper indentation and is
>> plain text, not html.
> 
> Also what I saw. Dave, do you get the newsgroup or the mailing list? I
> get the mailing list - it's possible the HTML version got stripped by
> Mailman.
> 

I'm using gmane newsgroup, and recently switched to the Android
 Newsgroup Reader. Previously was using Groundhog, which seemed to
 eat the body of any message containing an html part. (Though
 strangely it showed the footer in the tutor newsgroup). This one
 was mentioned byAlan, and she far has seemed much
 better.

-- 
DaveA



Android NewsGroup Reader
http://www.piaohong.tk/newsgroup

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Chris Angelico
On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly  wrote:
> On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel  wrote:
>> Next, please repost any source code with indentation preserved.
>>  Your message shows it all flushed to the left margin,  probably
>>  due to posting in html mode. Use text mode here.
>
> That's odd, the message that I got includes proper indentation and is
> plain text, not html.

Also what I saw. Dave, do you get the newsgroup or the mailing list? I
get the mailing list - it's possible the HTML version got stripped by
Mailman.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Ian Kelly
On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel  wrote:
> Next, please repost any source code with indentation preserved.
>  Your message shows it all flushed to the left margin,  probably
>  due to posting in html mode. Use text mode here.

That's odd, the message that I got includes proper indentation and is
plain text, not html.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Norman Elliott
I am running ubuntu 12.04 with all updates installed.

I got the graphics here:
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html

I cannot see how to change from html to text mode in chromium or within the 
group.

I read the link about double spacing so I will watch out for it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: plotting slows down

2014-01-13 Thread Norman Elliott
On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott  wrote:
> First let me say I have not done much python programming!
> 
> I am running Python 2.7.3.
> 
> I am trying to use python as a front end to a simple oscilloscope.
> 
> Ultimately I intend to use it with my micropython board.
> 
> 
> 
> At the moment I am just developing it. All it does is use a module I found 
> called graphics.py to create a window and display randomly generated data.
> 
> 
> 
> Each time it goes through the outer loop it gets slower and slower.
> 
> I put in a small delay just so I could observe what is happening and for the 
> first line it draws it takes about a second. If I set it to loop 20 times the 
> final loop takes more than 6 seconds.
> 
> Can anyone explain what I am doing wrong please?
> 
> Here is the code:
> 
> [code]
> 
> #!/usr/bin/python
> 
> from graphics import *
> 
> import random
> 
> import time
> 
> 
> 
> xpos=1200
> 
> ypos=400
> 
> ypnt=ypos/2
> 
> pos=1
> 
> #setBackground("white")
> 
> def main():
> 
>   win = GraphWin("My Circle", xpos, ypos)
> 
> # win.setBackGround('white')
> 
>   for y in range(1,5):
> 
>   cir2 = Circle(Point(xpos/2,20), 10)
> 
>   cir2.setFill("white")
> 
>   cir2.draw(win)
> 
>   message = Text(Point(win.getWidth()/2, 20), y)
> 
>   message.draw(win)
> 
>   j = random.randint(1,ypos)
> 
>   for x in range(1,xpos):
> 
>   updown = random.randint(0,1)
> 
>   if updown:
> 
>   j=j+1
> 
>   else:
> 
>   j=j-1
> 
>   if j <1:
> 
>   j=ypos/2
> 
>   if j>ypos-1:
> 
>   j=ypos/2
> 
>   win.plot(x,j,"red")
> 
>   time.sleep(.0001)
> 
> 
> 
> main()
> 
> time.sleep(5)
> 
> [/code]
-- 
https://mail.python.org/mailman/listinfo/python-list


plotting slows down

2014-01-13 Thread norman . elliott
First let me say I have not done much python programming!
I am running Python 2.7.3.
I am trying to use python as a front end to a simple oscilloscope.
Ultimately I intend to use it with my micropython board.

At the moment I am just developing it. All it does is use a module I found 
called graphics.py to create a window and display randomly generated data.

Each time it goes through the outer loop it gets slower and slower.
I put in a small delay just so I could observe what is happening and for the 
first line it draws it takes about a second. If I set it to loop 20 times the 
final loop takes more than 6 seconds.
Can anyone explain what I am doing wrong please?
Here is the code:
[code]
#!/usr/bin/python
from graphics import *
import random
import time

xpos=1200
ypos=400
ypnt=ypos/2
pos=1
#setBackground("white")
def main():
win = GraphWin("My Circle", xpos, ypos)
#   win.setBackGround('white')
for y in range(1,5):
cir2 = Circle(Point(xpos/2,20), 10)
cir2.setFill("white")
cir2.draw(win)
message = Text(Point(win.getWidth()/2, 20), y)
message.draw(win)
j = random.randint(1,ypos)
for x in range(1,xpos):
updown = random.randint(0,1)
if updown:
j=j+1
else:
j=j-1
if j <1:
j=ypos/2
if j>ypos-1:
j=ypos/2
win.plot(x,j,"red")
time.sleep(.0001)

main()
time.sleep(5)
[/code]


-- 
https://mail.python.org/mailman/listinfo/python-list