사용자 도구

사이트 도구


python:console

문서의 이전 판입니다!


Python Console

컬러 문자 출력

ascii문자로 plotting

ascii_plot.py
def ascii_plot(xs, ys):
    import subprocess
    import platform
    if platform.system().lower() == 'windows':
        path = 'C:/Program Files/gnuplot/bin/gnuplot.exe'
    else:
        path = "/usr/bin/gnuplot"
    gnuplot = subprocess.Popen([path], 
                                stdin=subprocess.PIPE, 
                                stdout=subprocess.PIPE, 
                                universal_newlines=True)
    input_string = "set term dumb 79 25\n"
    input_string += "set key off\n"
    input_string += "plot '-' using 1:2 title 'Line1' with linespoints \n"
    for i, j in zip(xs, ys):
        input_string += "%f %f\n" % (i, j)
    input_string += "e\n"
    output_string, error_msg = gnuplot.communicate(input_string)
    return output_string
 
 
if __name__ == '__main__':
    from tqdm import tqdm
    from time import sleep
    for freq in tqdm(range(10)):
        import numpy as np
        xs = np.linspace(0, 2 * np.pi, 100)
        ys = np.sin(freq * xs)
        o = ascii_plot(xs, ys)
        tqdm.write(o)
        sleep(1)

프로그래스 바 출력

UI

python/console.1518280884.txt.gz · 마지막으로 수정됨: (바깥 편집)