Hi Gökhan,

I recommend you to use matplotlib.widgets.RectangleSelector instead of the 
zoom functionality to select the data (An example can be found at 
http://matplotlib.sourceforge.net/examples/widgets/rectangle_selector.html ).
This will return you the x and y-coordinate of button press and button release 
event and with that you can take a portion of your data.
Something like the following could be a starting point:
x_min = min(eclick.xdata, erelease.xdata)
x_max = max(eclick.xdata, erelease.xdata)
x_new = x[(x>= x_min) & (x <= x_max)]

where eclick and erelease correspond to the click and release event of the 
rectangle selection (see the example below).

Opening a new figure after show can be achieved by:

fig_new = plt.figure()
# some plotting
fig_new.show()             # show up the new figure


best regards Matthias


yet another example for the usage of the RectangleSelector copied from its 
class documentation:

    """
    Select a min/max range of the x axes for a matplotlib Axes

    Example usage::

        from matplotlib.widgets import  RectangleSelector
        from pylab import *

        def onselect(eclick, erelease):
          'eclick and erelease are matplotlib events at press and release'
          print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
          print ' endposition   : (%f, %f)' % (erelease.xdata, erelease.ydata)
          print ' used button   : ', eclick.button

        def toggle_selector(event):
            print ' Key pressed.'
            if event.key in ['Q', 'q'] and toggle_selector.RS.active:
                print ' RectangleSelector deactivated.'
                toggle_selector.RS.set_active(False)
            if event.key in ['A', 'a'] and not toggle_selector.RS.active:
                print ' RectangleSelector activated.'
                toggle_selector.RS.set_active(True)

        x = arange(100)/(99.0)
        y = sin(x)
        fig = figure
        ax = subplot(111)
        ax.plot(x,y)

        toggle_selector.RS = RectangleSelector(ax, onselect, drawtype='line')
        connect('key_press_event', toggle_selector)
        show()
    """

On Friday 17 April 2009 02:26:51 Gökhan SEVER wrote:
> Hello,
>
> A quick question:
>
> I am using two numpy arrays to plot the figure shown in attachment. Is it
> possible to get array indices of selected X-axes while using the zoom
> function? Later I can create a new figure from this selected portion
> instead of the same figure and/or apply an analysis.
>
> Thank you.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to