Index: /branches/OpenElectrophy-0.2/OpenElectrophy/classes/analogsignal.py
===================================================================
--- /branches/OpenElectrophy-0.2/OpenElectrophy/classes/analogsignal.py	(revision 212)
+++ /branches/OpenElectrophy-0.2/OpenElectrophy/classes/analogsignal.py	(revision 249)
@@ -94,4 +94,8 @@
         if 'ax'in kargs:
             ax = kargs['ax']
+        else:
+            from matplotlib import pyplot
+            fig = pyplot.figure()
+            ax = fig.add_subplot(1,1,1)
         return ax.plot(self.t(), self.signal , color = color)
 
@@ -103,4 +107,9 @@
         if 'ax'in kargs:
             ax = kargs['ax']
+        else:
+            from matplotlib import pyplot
+            fig = pyplot.figure()
+            ax = fig.add_subplot(1,1,1)
+
         from ..computing.filter import fft_passband_filter
         nq = self.sampling_rate/2.
@@ -114,4 +123,9 @@
         if 'ax'in kargs:
             ax = kargs['ax']
+        else:
+            from matplotlib import pyplot
+            fig = pyplot.figure()
+            ax = fig.add_subplot(1,1,1)
+            
         from ..computing.timefrequency  import TimeFreq
         tf = TimeFreq(self, **kargs)
Index: /branches/OpenElectrophy-0.2/doc/source/installation.rst
===================================================================
--- /branches/OpenElectrophy-0.2/doc/source/installation.rst	(revision 226)
+++ /branches/OpenElectrophy-0.2/doc/source/installation.rst	(revision 249)
@@ -1,5 +1,6 @@
-************
+****************
 Installation
-************
+****************
+
 
 Introduction
@@ -99,5 +100,5 @@
 
 Upgrading 
-========
+===============
 
 Under linux in Possibility 1 or in Windows Step 3, remplace ::
Index: /branches/OpenElectrophy-0.2/doc/source/script.rst
===================================================================
--- /branches/OpenElectrophy-0.2/doc/source/script.rst	(revision 248)
+++ /branches/OpenElectrophy-0.2/doc/source/script.rst	(revision 249)
@@ -47,4 +47,14 @@
 
 
+Plotting 
+=============
+
+.. automodule:: plot_basic
+.. literalinclude:: ../../examples/plot_basic.py
+
+.. automodule:: plot_embeded
+.. literalinclude:: ../../examples/plot_embeded.py
+
+
 
 Computing
Index: /branches/OpenElectrophy-0.2/examples/sql_in_python_variable.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/sql_in_python_variable.py	(revision 248)
+++ /branches/OpenElectrophy-0.2/examples/sql_in_python_variable.py	(revision 249)
@@ -20,63 +20,64 @@
 sys.path.append('..')
 
-
-from OpenElectrophy import *
-from OpenElectrophy.io import ExampleIO
-import numpy
-from datetime import datetime
+if __name__== '__main__':
+    #start
 
 
-# connection to a DB
-url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
-open_db( url = url)
+    from OpenElectrophy import *
+    from OpenElectrophy.io import ExampleIO
+    import numpy
+    from datetime import datetime
 
 
-conditions = [ 'condition A', 'condition B', 'condition C']
+    # connection to a DB
+    url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
+    open_db( url = url)
 
 
-# create 5 block with 50 segment 
-# segment.info is the condition (randomly A B C)
-for i in range(5):
-    bl = Block( name = 'test')
-    id_block = bl.save()
-    for j in range(50):
-        c = int(numpy.random.rand()*3)
-        seg = Segment(  id_block = id_block,
-                                    name = 'seg test',
-                                    info = conditions[c],
-                                )
-        seg.save()
+    conditions = [ 'condition A', 'condition B', 'condition C']
+
+
+    # create 5 block with 50 segment 
+    # segment.info is the condition (randomly A B C)
+    for i in range(5):
+        bl = Block( name = 'test')
+        id_block = bl.save()
+        for j in range(50):
+            c = int(numpy.random.rand()*3)
+            seg = Segment(  id_block = id_block,
+                                        name = 'seg test',
+                                        info = conditions[c],
+                                    )
+            seg.save()
+            
     
+    # static query for block
+    query1 = """
+                    SELECT block.id
+                    FROM block
+                    LIMIT 5
+                    """
+    globals.globalsession.execute(query1)
+    id_blocks, = sql(query1)
+
+    for id_block in id_blocks:
+        print 'id_block', id_block
+        
+        # variable query
+        for condition in conditions:
+            query2 = """
+                            SELECT segment.id
+                            FROM segment
+                            WHERE
+                            segment.id_block = :id_block
+                            AND segment.info = :condition
+                            """
+            # variables are given in sql with dict
+            id_segments, = sql( query2, 
+                                                    id_block = id_block,
+                                                    condition = condition,
+                                                    )
+            print ' have ', len(id_segments), condition
 
 
 
-# static query for block
-query1 = """
-                SELECT block.id
-                FROM block
-                LIMIT 5
-                """
-globals.globalsession.execute(query1)
-id_blocks, = sql(query1)
-
-for id_block in id_blocks:
-    print 'id_block', id_block
-    
-    # variable query
-    for condition in conditions:
-        query2 = """
-                        SELECT segment.id
-                        FROM segment
-                        WHERE
-                        segment.id_block = :id_block
-                        AND segment.info = :condition
-                        """
-        # variables are given in sql with dict
-        id_segments, = sql( query2, 
-                                                id_block = id_block,
-                                                condition = condition,
-                                                )
-        print ' have ', len(id_segments), condition
-
-
-
Index: /branches/OpenElectrophy-0.2/examples/database_numpy.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/database_numpy.py	(revision 247)
+++ /branches/OpenElectrophy-0.2/examples/database_numpy.py	(revision 249)
@@ -10,14 +10,14 @@
 OpenElectrophy provide simple way to save a numpy field in SQL.
 This field is divide in 3 fields :
-    - the blob containing the buffer
-    - the dtype containing the array.dtyp
-    - the shape containing dimensions
+* the blob containing the buffer
+* the dtype containing the array.dtyp
+* the shape containing dimensions
 
 Theses classes have a numpy field:
-    AnalogSignal.signal
-    Spike.waveform
-    Oscillation.time_line
-    Oscillation.freq_line
-    Oscillation.value_line
+* AnalogSignal.signal
+* Spike.waveform
+* Oscillation.time_line
+* Oscillation.freq_line
+* Oscillation.value_line
 
 With the SQL mapper you can use them directly and transparently in yours scripts.
@@ -28,40 +28,26 @@
 sys.path.append('..')
 
+if __name__== '__main__':
+    
+    from OpenElectrophy import *
+    import numpy
+    # connection to a DB
+    url = 'sqlite:////home/sgarcia/test.db'
+    open_db( url = url)
 
-from OpenElectrophy import *
-import numpy
-# connection to a DB
-url = 'sqlite:////home/sgarcia/test.db'
-open_db( url = url)
+    # create an random AnalogSignal with 5. s at 1kHz
+    ana = AnalogSignal()
+    ana.signal = numpy.random.rand(5000)
+    ana.sampling_rate = 1000.
+    ana.t_start = 0.
 
-# create an random AnalogSignal with 5. s at 1kHz
-ana = AnalogSignal()
-ana.signal = numpy.random.rand(5000)
-ana.sampling_rate = 1000.
-ana.t_start = 0.
+    # ana.signal is a numpy.ndarray
+    print type(ana.signal)
 
-# ana.signal is a numpy.ndarray
-print type(ana.signal)
+    # so you can play with it
+    ana.signal[30:400] = 3.
+    ana.signal[ ana.signal>.8 ] *= 2.
 
-# so you can play with it
-ana.signal[30:400] = 3.
-ana.signal[ ana.signal>.8 ] *= 2.
+    # and save in db
+    ana.save()
 
-# and save in db
-ana.save()
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: /branches/OpenElectrophy-0.2/examples/plot_basic.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/plot_basic.py	(revision 249)
+++ /branches/OpenElectrophy-0.2/examples/plot_basic.py	(revision 249)
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+"""
+Basic and easy plot
+-----------------------------------------------
+
+OpenElectrophy use extensivly Matplotlib for plotting everythings in the GUI.
+
+You can also plot very easly every signal or spiketrain in scripts.
+
+The best is to read `matplotlib help <http://matplotlib.sourceforge.net/contents.html#t>`_ but you can start
+ without any knoledges just reading this example.
+ 
+Some classes (AnalogSignal, SpikeTrain, ...) have plot capabilities.
+
+The list of plot capabilities for each class is the same you can use in th GUI.
+
+ 
+"""
+
+import sys
+sys.path.append('..')
+
+
+if __name__== '__main__':
+
+
+    from OpenElectrophy import *
+    from OpenElectrophy.io import ExampleIO
+    
+    import numpy
+    from matplotlib import pyplot
+    
+    # create a random signal
+    ana = AnalogSignal(signal = numpy.random.randn(5000),
+                                        sampling_rate = 1000.,
+                                        name = 'noise',
+                                        )
+    
+    # AnalogSignal have 3 plotAptitudes:
+    ana.plot_natural( )
+    
+    ana.plot_filtered(f1 = 10, f2 = 100)
+    
+    ana.plot_scalogram(f_start = 10, f_stop = 500)
+    
+    
+    # you always need this to render figures on screen
+    pyplot.show()
+    
+    
Index: /branches/OpenElectrophy-0.2/examples/sql_in_python_and_loop.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/sql_in_python_and_loop.py	(revision 248)
+++ /branches/OpenElectrophy-0.2/examples/sql_in_python_and_loop.py	(revision 249)
@@ -15,72 +15,66 @@
 
 
-from OpenElectrophy import *
-from OpenElectrophy.io import ExampleIO
-import numpy
-from datetime import datetime
+if __name__== '__main__':
+
+    from OpenElectrophy import *
+    from OpenElectrophy.io import ExampleIO
+    import numpy
+    from datetime import datetime
 
 
-# connection to a DB
-url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
-open_db( url = url)
+    # connection to a DB
+    url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
+    open_db( url = url)
 
 
-# create 5 block with different date
-for i in range(5):
-    r = ExampleIO(filename='')
-    bl = r.read_block(   num_segment = 2   )
-    bl.datetime = datetime(2010, 06, 1+i, 12,30,40)
-    print bl.datetime
-    bl.name = 'test sql %d' %i
-    print bl.name
-    bl.save()
-    print bl.id
+    # create 5 block with different date
+    for i in range(5):
+        r = ExampleIO(filename='')
+        bl = r.read_block(   num_segment = 2   )
+        bl.datetime = datetime(2010, 06, 1+i, 12,30,40)
+        print bl.datetime
+        bl.name = 'test sql %d' %i
+        print bl.name
+        bl.save()
+        print bl.id
 
 
-# select all block.id after 3 june 2010 and segment name is 1
-query = """
-            SELECT block.id, segment.id, analogsignal.id
-            FROM block, segment, analogsignal
-            WHERE
-            block.id = segment.id_block
-            AND block.datetime > '2010-06-03'
-            AND segment.name = 'example segment 1'
-            
-            LIMIT 10
-            """
-id_blocks, id_segments, id_analogsignals= sql(query)
+    # select all block.id after 3 june 2010 and segment name is 1
+    query = """
+                SELECT block.id, segment.id, analogsignal.id
+                FROM block, segment, analogsignal
+                WHERE
+                block.id = segment.id_block
+                AND block.datetime > '2010-06-03'
+                AND segment.name = 'example segment 1'
+                
+                LIMIT 10
+                """
+    id_blocks, id_segments, id_analogsignals= sql(query)
 
-for i in range(id_blocks.size):
-    print i
-    print ' id_block', id_blocks[i]
-    print ' id_segment', id_segments[i]
-    print ' id_analogsignal', id_analogsignals[i]
-    
-    # load the block
-    bl = Block()
-    bl.load( id_blocks[i])
-    print ' ',bl.name
-    
-    # load the segment
-    seg = Segment()
-    seg.load( id_segments[i] )
-    print ' ',seg.name
-    
-    
-    # load the AnalogSignal
-    ana = AnalogSignal()
-    ana.load( id_analogsignals[i] )
-    print ' ', ana.name
-    
-    print ' ', ana.signal.size
-    rms = numpy.sqrt( numpy.mean( (ana.signal**2.) ) )
-    print '     rms', rms
-    
-    
-    
-    
-    
-    
-    
+    for i in range(id_blocks.size):
+        print i
+        print ' id_block', id_blocks[i]
+        print ' id_segment', id_segments[i]
+        print ' id_analogsignal', id_analogsignals[i]
+        
+        # load the block
+        bl = Block()
+        bl.load( id_blocks[i])
+        print ' ',bl.name
+        
+        # load the segment
+        seg = Segment()
+        seg.load( id_segments[i] )
+        print ' ',seg.name
+        
+        
+        # load the AnalogSignal
+        ana = AnalogSignal()
+        ana.load( id_analogsignals[i] )
+        print ' ', ana.name
+        
+        print ' ', ana.signal.size
+        rms = numpy.sqrt( numpy.mean( (ana.signal**2.) ) )
+        print '     rms', rms
 
-
Index: /branches/OpenElectrophy-0.2/examples/plot_embeded.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/plot_embeded.py	(revision 249)
+++ /branches/OpenElectrophy-0.2/examples/plot_embeded.py	(revision 249)
@@ -0,0 +1,52 @@
+
+# -*- coding: utf-8 -*-
+"""
+Plot in existing figures
+-----------------------------------------------
+
+If you want to plot data in more complexe figures you can can ax argument to plot somthing in
+an existing figure.
+
+
+
+ 
+"""
+
+import sys
+sys.path.append('..')
+
+
+if __name__== '__main__':
+
+
+    from OpenElectrophy import *
+    from OpenElectrophy.io import ExampleIO
+    
+    import numpy
+    from matplotlib import pyplot
+    
+    fig = pyplot.figure()
+    ax1 = fig.add_subplot(2,2,1)
+    ax2 = fig.add_subplot(2,2,2)
+    ax3 = fig.add_subplot(2,2,3)
+    ax4 = fig.add_subplot(2,2,4)    
+    
+    # create a random signal
+    ana = AnalogSignal(signal = numpy.random.randn(5000),
+                                        sampling_rate = 1000.,
+                                        name = 'noise',
+                                        )
+    
+    # AnalogSignal have 3 plotAptitudes:
+    ana.plot_natural( ax = ax1)
+    ana.plot_filtered(f1 = 10, f2 = 100, ax = ax2)
+    ana.plot_filtered(f1 = 100, f2 = 300, ax=ax3) 
+    ana.plot_scalogram(f_start = 10, f_stop = 500 , ax = ax4)
+    
+    
+    # you always need this to render figures on screen
+    pyplot.show()
+
+
+
+    
Index: /branches/OpenElectrophy-0.2/examples/database_load_and_save_basic.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/database_load_and_save_basic.py	(revision 247)
+++ /branches/OpenElectrophy-0.2/examples/database_load_and_save_basic.py	(revision 249)
@@ -27,47 +27,42 @@
 sys.path.append('..')
 
+if __name__== '__main__':
 
-from OpenElectrophy import *
+    from OpenElectrophy import *
 
-# connection to a DB
-#~ url = 'sqlite:///~test.db'
-url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
-open_db( url = url)
+    # connection to a DB
+    #~ url = 'sqlite:///~test.db'
+    url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
+    open_db( url = url)
 
 
-# create an empty segment variable
-seg1 = Segment()
+    # create an empty segment variable
+    seg1 = Segment()
 
-# fill fields
-seg1.name = 'My first segment'
-seg1.info = 'This is just a test'
+    # fill fields
+    seg1.name = 'My first segment'
+    seg1.info = 'This is just a test'
 
-# TEXT field in SQL = str in python
-print seg1.name
-print type(seg1.name)
+    # TEXT field in SQL = str in python
+    print seg1.name
+    print type(seg1.name)
 
-print seg1.id
-# give None
+    print seg1.id
+    # give None
 
-# SAVE seg1 to the db (return the id)
-id =  seg1.save()
-print  id
+    # SAVE seg1 to the db (return the id)
+    id =  seg1.save()
+    print  id
 
-# now the id of seg1 is not anymore None
-print seg1.id
+    # now the id of seg1 is not anymore None
+    print seg1.id
 
 
 
-# LOAD from a the db
+    # LOAD from a the db
 
-# create an empy segment
-seg2 = Segment()
-seg2.load( id )
-print seg2.id
-print seg2.name
-
-
-
-
-
-
+    # create an empy segment
+    seg2 = Segment()
+    seg2.load( id )
+    print seg2.id
+    print seg2.name
Index: /branches/OpenElectrophy-0.2/examples/database_update.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/database_update.py	(revision 247)
+++ /branches/OpenElectrophy-0.2/examples/database_update.py	(revision 249)
@@ -6,7 +6,7 @@
 If you to update a row.
 It is easy :
-    - Load an object
-    - modify attribute
-    - Save object
+* Load an object
+* modify attribute
+* Save object
 
 
@@ -16,20 +16,21 @@
 sys.path.append('..')
 
+if __name__== '__main__':
 
-from OpenElectrophy import *
-# connection to a DB
-url = 'sqlite:///~test.db'
-url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
-open_db( url = url)
+    from OpenElectrophy import *
+    # connection to a DB
+    url = 'sqlite:///~test.db'
+    url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
+    open_db( url = url)
 
 
-# I know the ID
-id= 34
-seg = Segment()
-seg.load(id)
+    # I know the ID
+    id= 34
+    seg = Segment()
+    seg.load(id)
 
-# Modify attribute
-seg.name = 'modified name'
+    # Modify attribute
+    seg.name = 'modified name'
 
-# save 
-seg.save()
+    # save 
+    seg.save()
Index: /branches/OpenElectrophy-0.2/examples/open_a_db.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/open_a_db.py	(revision 247)
+++ /branches/OpenElectrophy-0.2/examples/open_a_db.py	(revision 249)
@@ -28,12 +28,13 @@
 sys.path.append('..')
 
+if __name__== '__main__':
 
-from OpenElectrophy import open_db
-# connection to a DB
-url = 'sqlite:////home/sgarcia/test.db'
-open_db( url = url)
+    from OpenElectrophy import open_db
+    # connection to a DB
+    url = 'sqlite:////home/sgarcia/test.db'
+    open_db( url = url)
 
-url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
-open_db( url = url)
+    url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
+    open_db( url = url)
 
 
Index: /branches/OpenElectrophy-0.2/examples/sql_in_python_basic.py
===================================================================
--- /branches/OpenElectrophy-0.2/examples/sql_in_python_basic.py	(revision 248)
+++ /branches/OpenElectrophy-0.2/examples/sql_in_python_basic.py	(revision 249)
@@ -24,70 +24,69 @@
 
 
-from OpenElectrophy import *
-from OpenElectrophy.io import ExampleIO
-import numpy
-from datetime import datetime
+if __name__== '__main__':
 
 
-# connection to a DB
-url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
-open_db( url = url)
+    from OpenElectrophy import *
+    from OpenElectrophy.io import ExampleIO
+    import numpy
+    from datetime import datetime
 
 
-# create 5 block with different date
-for i in range(5):
-    r = ExampleIO(filename='')
-    bl = r.read_block(      )
-    bl.datetime = datetime(2010, 06, 1+i, 12,30,40)
-    print bl.datetime
-    bl.name = 'test sql %d' %i
-    print bl.name
-    bl.save()
-    print bl.id
+    # connection to a DB
+    url = 'mysql://test_dev:test_dev@neuro001.univ-lyon1.fr/test_dev_1'
+    open_db( url = url)
 
-# select all block.id after 3 june 2010
-query = """
-            SELECT block.id, block.name
-            FROM block
-            WHERE
-            block.datetime > '2010-06-03'
-            """
-ids, names = sql(query)
-print ids
-print names
-print type(names)
+
+    # create 5 block with different date
+    for i in range(5):
+        r = ExampleIO(filename='')
+        bl = r.read_block(      )
+        bl.datetime = datetime(2010, 06, 1+i, 12,30,40)
+        print bl.datetime
+        bl.name = 'test sql %d' %i
+        print bl.name
+        bl.save()
+        print bl.id
+
+    # select all block.id after 3 june 2010
+    query = """
+                SELECT block.id, block.name
+                FROM block
+                WHERE
+                block.datetime > '2010-06-03'
+                """
+    ids, names = sql(query)
+    print ids
+    print names
+    print type(names)
 
 
 
-# be CAREFULL if you select only one column
-# you need a coma even for one column
+    # be CAREFULL if you select only one column
+    # you need a coma even for one column
 
-# GOOD
-query = """
-            SELECT block.name
-            FROM block
-            WHERE
-            block.datetime > '2010-06-03'
-            """
-names, = sql(query)
-print names #[test sql 2 test sql 3 test sql 4]
-print type(names) #<type 'numpy.ndarray'>
-print len(names) # 3
-# names is a ndarray
+    # GOOD
+    query = """
+                SELECT block.name
+                FROM block
+                WHERE
+                block.datetime > '2010-06-03'
+                """
+    names, = sql(query)
+    print names #[test sql 2 test sql 3 test sql 4]
+    print type(names) #<type 'numpy.ndarray'>
+    print len(names) # 3
+    # names is a ndarray
 
 
-# BAD
-query = """
-            SELECT block.name
-            FROM block
-            WHERE
-            block.datetime > '2010-06-03'
-            """
-names = sql(query)
-print names #array([test sql 2, test sql 3, test sql 4], dtype=object)]
-print type(names) #<type 'list'>
-print len(names) # 1
-
-
-
-
+    # BAD
+    query = """
+                SELECT block.name
+                FROM block
+                WHERE
+                block.datetime > '2010-06-03'
+                """
+    names = sql(query)
+    print names #array([test sql 2, test sql 3, test sql 4], dtype=object)]
+    print type(names) #<type 'list'>
+    print len(names) # 1
