본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 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>


'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 27  (0) 2019.04.26
Python Learn the basics Quiz 26  (0) 2019.04.13
Python Learn the basics Quiz 25  (0) 2019.04.13
Python Learn the basics Quiz 24  (0) 2019.04.13
Python Learn the basics Quiz 23  (0) 2019.04.08
Python Learn the basics Quiz 22  (0) 2019.03.30