Python Forum
Optimised Display - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Optimised Display (/thread-11698.html)



Optimised Display - Astrikor - Jul-22-2018

I a newbie seeking help on control of the displayed print screen.
I have a small array (4,20) which updates very fast and the printed array appendes to the bottom of the previous printout.

I would like to watch the printout to see updates as they occur in each cell.

So I am looking for python/numpy code for screen overwrite (I have tried os.clr without success)

Ideas appreciated!


RE: Optimised Display - Larz60+ - Jul-22-2018

for terminal like screens, see: https://docs.python.org/3/howto/curses.html


RE: Optimised Display - Astrikor - Jul-23-2018

Thanks Larz60+ but that's very opaque for a newbie!

I guess I am really asking how to clear (or overwrite or retrace) the shell window.

My searches have not provided anything useful so far.

Maybe it can't be done?

Now there's a challenge !!


RE: Optimised Display - Astrikor - Jul-24-2018

As no-one has yet come up with a simple suggestion, I have resolved the issue by saving the array to a CSV file in Dropbox which I can visit to view the array to check on performance. The downside of this solution is that the array is temporarily unavailable for updating in the program until I close the CSV file.

However, it is a (marginally) acceptable solution.

Incidentally, I also tried a Tkinter window solution, which gave a good display of the array, but stopped the loop running.

Thanks Guys for following this thread.

Astrikor


RE: Optimised Display - Larz60+ - Jul-24-2018

Trying to solve a problem without seeing the code is kind of like performing brain surgery in the dark. It's
next to impossible.
If you post code (which ever version you like best), I'm sure you will get some (at least possible) solutions.


RE: Optimised Display - Astrikor - Jul-25-2018

Ok, this trivial code will illustrate the point - you cant watch the changes to the array unless it shows a stable print on the screen, and even if you adjust the window height manually to show just 4 lines, ultimately the loop crashes (exceeds max shell limit ?). Consequently I was looking for some code to either clear the shell display or alternatively to overwrite the previous loop cycle.
import numpy as np
myarray = np.zeros([4,10])
print(myarray)
while True:
    for i in range(4):
        myarray[i,0] = 1 + myarray[i,0]
    print(myarray)



RE: Optimised Display - dageci - Jul-26-2018

Hello maybe you could use this:

import os

def clearscr():
    os.system('cls' if os.name=='nt' else 'clear')

# in your code to clear the screen call this function
clearscr()



RE: Optimised Display - Astrikor - Jul-26-2018

Thanks dageci
You mean like this ?
import numpy as np
import os
 
def clearscr():
    os.system('cls' if os.name=='nt' else 'clear')
 
# in your code to clear the screen call this function
clearscr()
myarray = np.zeros([4,10])
print(myarray)
while True:
    for i in range(4):
        myarray[i,0] = 1 + myarray[i,0]
    print(myarray)
    clearscr()
Try it - it doesn't work!

Any other suggestions please?
Astrikor


RE: Optimised Display - dageci - Jul-26-2018

Maybe this link can help.
https://teamtreehouse.com/community/clear-screen-for-pycharm-as-if-it-were-on-console-or-cmd

They are talking that the only solution could be to assign a shortcut key to Clear all button and then emulating Key presses for that shortcut keys.