2015/07/23

초등학교 4학년 막대그래프 그리기

파이선 스크립트로 간단한 막대그래프 그리기를 만들어봤습니다. 정말 간단합니다. ^^;;

--------------------------
#-*- coding: utf-8 -*-

import sys
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams

X = []
Y = []

while True:
    try:
        x = input("input X: ")
    except:
        break

    if x == '':
        break

    try:
        y = input("input Y: ")
    except:
        break

    if y == '':
        break

    if type(x) is not str:
        if int(x) == float(x):
            x = int(x)
        else:
            x = float(x)

    if int(y) == float(y):
        y = int(y)
    else:
        y = float(y)

    X += [x]
    Y += [y]

if len(X) == 0:
    sys.exit()

ind = np.arange( len(X) )
width = 0.35

plt.plot()
plt.bar( ind, Y, 0.3 )
plt.xticks( ind+width/2., X, family = ['Noto Sans Korean'] )
plt.ylim( 0, max(Y) + int( max(Y)/10.0 ) )
plt.show()
--------------------

numpy가 필요없을 것 같은데, 기왕 집어넣은 거 냅두기로 했습니다.

- python버전은 3.x입니다.
- 우분투(리눅스) 환경에서 구동해봤습니다.

댓글 없음: