2018-05-31

posted May 31, 2018, 5:51 AM by Konstantinovich Samuel   [ updated Jun 6, 2018, 6:47 AM ]

Stuyvesant is forming a partnership with Google to create a project mentorship program that will being next fall. The program will focus on pairing groups of students (1-4) with Google employees who will help them create a substantial software project. 
There will be an info session for this program TODAY (5/31) at 4pm in room 307. The program will be open to rising Juniors and Seniors.


1. Make a folder in the same directory as your py file to hold your images. 
mkdir img

Then change the permissions to 777. This will allow
chmod 777 img

Now you have a folder to store your images, and the following script would work:

#!/usr/bin/python
print "Content-type: text/html\n"

#help you see errors
import cgitb
cgitb.enable()
#these 3 lines are important
#matplotlib allows you to use the graphing tools on a web server
#the Agg line is required to work without a graphical desktop (running on a remote computer)
import matplotlib matplotlib.use("Agg")
import matplotlib.pyplot as plt

def main():
        x=[0,1,2,3,4] 
        y=[0,3,5,9,3]
        plt.plot(x,y) 
        plt.savefig("img/graph.png")

        plt.clf() #clear the figure after saving!

        
        x = [0.1,0.2,0.1,0.3,0.9]
        y = [0.9,0.4,0.2,0.5,0.2]
        plt.scatter(x, y,  alpha=0.5)
        plt.savefig("img/graph2.png")

        print "Done!<br>"
        print "Image?<br>"
        print '<img src="img/graph.png">'
        print "Another Image!<br>"
        print '<img src="img/graph2.png">'
head = '''<!DOCTYPE html> <html> <head> <title>Demo!</title> </head> <body>''' print head #main will print things main() print ''' </body> </html>'''
Comments