What I’m trying to do could be written like this:
import pylab
class GetsDrawn(object):
def __init__(self):
self.x=some_function_that_returns_an_array()
self.y=some_other_function_that_returns_an_array()
# verison 1: pass in figure/subplot arguments
def draw(self, fig_num, subplot_args ):
pylab.figure(fig_num)
pylab.subplot( *subplot_args )
pylab.scatter( self.x, self.y)
i.e. I could tell the object “where” to draw itself via a figure-number and sub-plot configuration.
I suspect that a version which is passed a pylab object would be more flexible in the
long run, but don’t know what type of object(s) to provide to the function.
For scripts, it is generally preferred to use the object oriented api.
For example, you can let your function receive a figure:
If your function actually draws only on one axes, you can even pass that as an object:
To create a figure use:
and to create for example a figure with one subplot on it, use:
The last command only exists in recent versions if I am not mistaken.