Closed GoogleCodeExporter closed 8 years ago
It seems to me that we could use the canvas in its current form for this. We
just
need to add a couple of new functions to the graphics API - one to display an
image
from a file, another from a string of bytes.
Original comment by johannes...@gmail.com
on 19 Jan 2008 at 9:50
Following suggestion from Comment 1, I implemented a simple function to do this
(revision 559). To test: go to the graphics page (link on left menu) and
enter the
following code at an interpreter:
import graphics as g
g.init_graphics()
g.display_image('ball.png')
I'm leaving this issue open as this method could be improved (for example, we
could
have a function that does not require to call init_graphics() first.
Original comment by andre.ro...@gmail.com
on 19 Jan 2008 at 10:28
This method appears to work only with images normally accessible from the server
root. We need to have a method that would work for images located on arbitrary
locations.
Original comment by andre.ro...@gmail.com
on 19 Jan 2008 at 10:52
It looks like a mixture of dynamic generation of an image element (like we do
for the
canvas) and the vlam_image_file.py is likely to be a better and more flexible
approach.
Original comment by andre.ro...@gmail.com
on 19 Jan 2008 at 11:19
Fixed with revision 560!!!
Here's an example that can be run from an editor (assuming matplotlib is
installed)
import os
import image_display
chosen_path = os.path.expanduser("~")
os.chdir(chosen_path)
# assumes matplotlib is installed
import matplotlib.numerix as nx
import pylab as p
def boltzman(x, xmid, tau):
"""
evaluate the boltzman function with midpoint
xmid and time constant tau over x
"""
return 1. / (1. + nx.exp(-(x-xmid)/tau))
def fill_below_intersection(x, S, Z):
"""
fill the region below the intersection of S and Z
"""
#find the intersection point
ind = nx.nonzero( nx.absolute(S-Z)==min(nx.absolute(S-Z)))[0]
# compute a new curve which we will fill below
Y = nx.zeros(S.shape, typecode=nx.Float)
Y[:ind] = S[:ind] # Y is S up to the intersection
Y[ind:] = Z[ind:] # and Z beyond it
p.fill(x, Y, facecolor='blue', alpha=0.5)
x = nx.arange(-6, 6, .01)
S = boltzman(x, 0, 1)
Z = 1-boltzman(x, 0.5, 1)
p.plot(x, S, x, Z, color='red', lw=2)
fill_below_intersection(x, S, Z)
# save image and display it.
p.savefig("foo.png")
image_path = os.path.join(chosen_path, "foo.png")
image_display.show(image_path)
Original comment by andre.ro...@gmail.com
on 20 Jan 2008 at 1:15
Original issue reported on code.google.com by
andre.ro...@gmail.com
on 13 Dec 2007 at 8:20