#from udacityplots import *
import warnings
warnings.filterwarnings("ignore")



import matplotlib 
#無視窗框
matplotlib.use('agg')


#引入繪圖工具
import matplotlib.pyplot as plt
import pylab as pl
import numpy as np

#引入顯示開啟圖片的套件
from PIL import Image
#import numpy as np
#import matplotlib.pyplot as plt
#plt.ioff()

#產生圖片 (將分類器畫出的線  跟訓練資料點作出)
def prettyPicture(clf, X_test, y_test):
	#邊界
	x_min = 0.0; x_max = 1.0
	y_min = 0.0; y_max = 1.0

    # Plot the decision boundary. For that, we will assign a color to each
    # point in the mesh [x_min, m_max]x[y_min, y_max].
	
	h = .01  # step size in the mesh
	#根據給定的座標建立座標矩陣  由大到小每隔h取點
	xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
	
	
	Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

    # Put the result into a color plot
	Z = Z.reshape(xx.shape)
	plt.xlim(xx.min(), xx.max())
	plt.ylim(yy.min(), yy.max())

	plt.pcolormesh(xx, yy, Z, cmap=pl.cm.seismic)

    # Plot also the test points
	grade_sig = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==0]
	bumpy_sig = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==0]
	grade_bkg = [X_test[ii][0] for ii in range(0, len(X_test)) if y_test[ii]==1]
	bumpy_bkg = [X_test[ii][1] for ii in range(0, len(X_test)) if y_test[ii]==1]

	plt.scatter(grade_sig, bumpy_sig, color = "b", label="fast")
	plt.scatter(grade_bkg, bumpy_bkg, color = "r", label="slow")
	plt.legend()
	plt.xlabel("bumpiness")
	plt.ylabel("grade")
	plt.show()
	plt.savefig("test.png")
	
	print("img saved!!")
	
import base64
import json
import subprocess


#修改後函式
def output_image(name):
	img=Image.open(name)
	img.show()



#原函式內容
# def output_image(name, format, bytes):
	# image_start = "BEGIN_IMAGE_f9825uweof8jw9fj4r8"
	# image_end = "END_IMAGE_0238jfw08fjsiufhw8frs"
	# data = {}
	# data['name'] = name
	# data['format'] = format
	# data['bytes'] = base64.encodestring(bytes)
	# print image_start+json.dumps(data)+image_end