공부중, Pandas Library에 내장되어있는, plot 함수로 차트를 그리는 예제가 나왔는데,

주피터 노트북에서 실행을 하니 아래와 같은 메세지만 나오고 실제 차트가 나오지 않는다...

Pandas 자체 내장 plot 함수 뿐만 아니라, 파이썬에서 유명한 plot library인 matplotlib을 돌려도 동일한 상태...

먼일이지??.... 실행 메세지는 정상으로 떳는데 차트가 안나온다

 

나중에 알고보니, matplotlib 에 show()라는 함수가 있어, xx.show()를 해줘야 최종적으로 차트가 보이는 구조로 동작하는 듯 했다. 그런데.. 인간의 욕심은 끝이 없듯이... 뭔가 plot 함수를 쓰면 바로 차트가 툭 튀어나와서 내 눈을 즐겁게 해주는 상황을 만들고 싶어졌다.

언제나 처럼 문제에 직면하면 매트릭스의 Oracle을 만나듯, 구글로 회귀를 하게되는데, 역시나! matplotlib 기반 차트를 보려면 아래와 같은 옵션을 사전 실행해줘야되더라. Pandas 내장 plot library또한 matplotlib을 가지고와서 쓰는 구조라서 그런지 모르겠는데, 여튼 아래와 같은 차트를 보려면 아래와 같이 '%' 기호로 시작하는 'python magic command'를 써줘야 한다.

결론만 이야기 하면, 

%matplotlib inline: Image 형태로 차트를 노트북 내에 그림

%matplotlib inline

%matplotlib notebook: chart를 cell에 그리되 Interactive 하기 사용자가 크기조절 등을 할 수 있는 mode로 보여줌 

%matplotlib notebook

 

* Python magic command란? (귀찮으니 원문 첨부 )

from : https://ipython.readthedocs.io/en/stable/interactive/tutorial.html#magics-explained

IPython has a set of predefined ‘magic functions’ that you can call with a command line style syntax. There are two kinds of magics, line-oriented and cell-oriented. Line magics are prefixed with the % character and work much like OS command-line calls: they get as an argument the rest of the line, where arguments are passed without parentheses or quotes. Lines magics can return results and can be used in the right hand side of an assignment. Cell magics are prefixed with a double %%, and they are functions that get as an argument not only the rest of the line, but also the lines below it in a separate argument.

 

 

반응형

+ Recent posts