traditional tk inter problem
Will Stuyvesant
hwlgw at hotmail.com
Wed Jan 29 18:32:24 EST 2003
[Chris Lyon]
> ... and all I really want to do it plot a graph in a webpage...
Try this:
$ python antisulk.py > p.html
and see whats in there.
-------- antisulk.py --------------------------------------
def myFunction(x):
import math
return math.sin(x)
whyHTML = '''
<p style="width:400px; margin-left:50px">
This is for Chris Lyon who just wants to plot a graph
on a webpage. I can't help you with linux. Actually I
quit linux myself because of all those configuration
problems over and over again. But how about plotting a
graph on a webpage *without using images*? If you hold
the mouse over the graph it shows you the coordinates
in a popup help window. Well, at least it does with my
IE6 browser. Have fun with CSS !
</p>
'''
startHTML = '''<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<style type="text/css">
body, .dot {
color: gray; font-size: large;
font-family: "Courier";
padding: 10%;
}
.dot {
position: absolute;
}
</style>
<title>
The map
</title>
</head>
<body>
'''
endHTML = '''</body>
</html>
'''
def graphHTML(myFunc, xBegin, xEnd,
size=400, offsetX=50, offsetY=500, yScale=200):
''' build HTML for graphplot'''
result = ''
for px in range(0, size):
x = px * ((xEnd - xBegin) / (1.0 * size))
y = myFunc(x)
py = y*yScale
result = result + '''
<span title='(%s,%s)' class=dot
style="left:%spx; top:%spx;">.</span>'''%(
x, y, px+offsetX, offsetY-py)
return result
def run():
print startHTML
print whyHTML
print '<br><br><br>'
print graphHTML(myFunction, 0, 6.5)
print endHTML
if __name__ == '__main__':
run()
More information about the Python-list
mailing list