Python_Matter/Solve

Python Learn the basics Quiz 25

AnKiWoong 2019. 4. 13. 12:25
반응형

Q>

아래에 도표는 각 년도 출생아 수를 나타낸다.

이 도표를 막대그래프와 선 그래프를 사용하여 그래프를 생성하시오.

년도 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017
출생아수 465892 44849 470171 471265 484550 436455 435435 438420 406243 357771


A>

import matplotlib.pyplot as pyplot

newborn = [465892, 444849, 470171, 471265, 484550, 436455, 435435, 438420, 406243, 357771]
year = [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017]

pyplot.rcParams["font.family"] = 'Malgun Gothic'
pyplot.rcParams["font.size"] = 12
pyplot.rcParams["figure.figsize"] = (10, 20)

pyplot.figure()
pyplot.plot(year, newborn, linestyle='--', marker='.', color='#ff6600')
pyplot.bar(year, newborn, label='출생 수', color='#f6e640')
pyplot.legend()
pyplot.xlabel('년도')
pyplot.ylabel('출생아 수')
pyplot.ylim(350000, 490000)
pyplot.title('년도별 출생아 수')
pyplot.grid()

for i, v in enumerate(year):
str_val = "%d명" % newborn[i]

pyplot.text(v, newborn[i], str_val, fontsize=9, color='#000000',
horizontalalignment='center', verticalalignment='bottom')

pyplot.show()
pyplot.close()


O>


반응형