php에서 python 결과 출력하기 시도를 한 과정입니다.
ETC
2016. 4. 9. 12:30
http://gildang.co.kr/?p=2331
php에서 python 결과 출력하기 시도를 한 과정입니다.
안녕하세요, 저는 길당 홍길한이라 합니다.
한동안 저는 php 에서 다음과 같은 python code를
- #!/usr/bin/python
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib
- matplotlib.style.use('ggplot')
- ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
- ts = ts.cumsum()
- plt.figure()
- ts.plot()
- plt.savefig("foo.png", bbox_inches='tight')
어떻게 하면
표현할 수 있을지 고민을 하여 왔습니다.
그래서 오늘 고민 끝에 우선 다음과 같이 위의 코드를 실행하고 나면,
foo.png라는 파일이 생성되고 ,
그 파일을 다음과 같이
html 파일에 img 태그로 insert 하여 준 다음에,
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Good morning</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <link rel="Stylesheet" type="text/css" href="goodmorning.css" />
- </head>
- <body>
- <div id="container">
- <div id="header">
- <h1> Your website name </h1>
- <ul id="mainmenu">
- <li class="active"><a href="http://all-free-download.com/free-website-templates/">Home</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">About</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Contact</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Guestbook</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Links</a></li>
- </ul>
- </div>
- <div id="content">
- <!-- CONTENT START -->
- <h2>About the Template</h2>
- <p>The header image is a drawing I made a long time ago for some other design, but it was not used.
- It's pretty simple-looking, and I believe it makes a great blog template.</p>
- <p>It's tested in <a href="http://all-free-download.com/free-website-templates/">Mozilla Firefox 2.0</a>, <a href="http://all-free-download.com/free-website-templates/">Internet Explorer 6 & 7</a>, <a href="http://all-free-download.com/free-website-templates/">Opera 9</a>, and <a href="http://all-free-download.com/free-website-templates/">Netscape 7.2</a>,
- on resolution 800x600 and
- 1024x768, and works good in each of the mentioned. It is also validated <a href="http://validator.w3.org/check?uri=referer">XHTML</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>. </p>
- <h2>Terms of Service</h2>
- <p>This work is released under the <a href="http://creativecommons.org/licenses/by-nc-nd/2.5/" title="Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License">Creative Commons Licence</a>.</p>
- <ol>
- <li>Leave the credit and link back to http://inobscuro.com/http://inobscuro.com/</a> visible.</li>
- <li>Do not redistribute.</li>
- <li>Personal, non-profit use only.</li>
- <li>Derivative work prohibited.</li>
- </ol>
- <h2>Instructions for Installation</h2>
- <ul>
- <li>Download the .ZIP file containing the entire template;</li>
- <li>Unzip the file. Use software like WinRAR, WinZIP, StuffIt etc.
- (If you have Windows XP then you don't need to download any additional software);</li>
- <li>Open the file <strong>index.html</strong> in your text editor (Notepad) and edit the website title, content
- and links in the navigation area. (Those areas are marked with comments.)
- Save edited files under corresponding names (for example <i>about.html</i>, <i>links.html</i>...);</li>
- <li>Upload all the files and folders to your server.</li>
- </ul>
- <img style="display: none;" src="aaa.php">
- <p>Have fun and enjoy :)</p>
- <img width="150px" height="150px" src="foo.png">
- <!-- CONTENT END -->
- </div>
- <div id="column">
- <!-- NAVIGATION START -->
- <h3>About...</h3>
- <p>You can write something here if you like. Or put a cam, or shoutbox. <a href="http://all-free-download.com/free-website-templates/">A link</a>.</p>
- <h3>Network</h3>
- <ul class="menu">
- <li><a href="http://all-free-download.com/free-website-templates/">Website Link Here</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Website Link Here</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Website Link Here</a></li>
- </ul>
- <h3>Affiliates</h3>
- <ul class="menu">
- <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
- <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
- </ul>
- <!-- NAVIGATION END -->
- </div>
- </div>
- <div id="footer">
- <p>
- <!-- COPYRIGHT INOFRMATION -->
- Copyright © 2006-2007 <a href="http://all-free-download.com/free-website-templates/">Your Name</a>
- <!-- COPYRIGHT INOFRMATION END -->
- </p>
- <p class="credit"> Designed by: <a href="http://inobscuro.com/">In obscuro</a> </p>
- </div>
- <div align=center>This template downloaded form <a href='http://all-free-download.com/free-website-templates/'>free website templates</a></div></body>
- </html>
- <img width="150px" height="150px" src="foo.png">
이 png 파일을 우선 저는 test.html이라고 하여 준 다음에,
마지막으로 ,
php 파일에서 test.html을 include 하여 불러 들였습니다.
- <?php
- include("test.html");
- ?>
이제 결과는 다음과 같습니다.