1
간단한 플롯 (StringIO에 저장 됨)을 웹 브라우저로 반환하려고합니다. 독서의 시간 후에, 마침내 가까워지고있어, 아마.cStringIO를 사용하여 CGI에 matplotlib 플롯 표시
import cgi
import cStringIO
import matplotlib.pyplot as plt
import numpy as np
def doit():
x = np.linspace(-2,2,100)
y = np.sin(x)
format = "png"
ggg = cStringIO.StringIO()
plt.plot(x, y)
plt.savefig(ggg, format=format)
data_uri = ggg.read().encode('base64').replace('\n', '')
img_tag = '<img src="data:image/png;base64,{0}" alt="thisistheplot"/>'.format(data_uri)
print("Content-type: text/html\n")
print("<title>Try Ageen</title>")
print("<h1>Hi</h1>")
print(img_tag)
doit()
깨진 이미지 아이콘이 반환됩니다. 나는 이미 이것을 보았습니다 : Dynamically serving a matplotlib image to the web using python, 다른 사람들 중에서 ...