Getting arrax indices using the zoom tool

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.

zooming.png

···


Gökhan

Not an answer to your question but ...
I think a log scale would be more informative.

Alan Isaac

···

On 4/16/2009 8:26 PM Gökhan SEVER apparently wrote:

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.

Thanks for the suggestion Alan.

This is just a preliminary data --needs to be gone over and edited unreasonable peaks.

By the way the data is from a cloud condensation nuclei counter.

···

On Thu, Apr 16, 2009 at 8:51 PM, Alan G Isaac <alan.isaac@…985…> wrote:

On 4/16/2009 8:26 PM Gökhan SEVER apparently wrote:

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.

Not an answer to your question but …

I think a log scale would be more informative.

Alan Isaac


Stay on top of everything new and different, both inside and

around Java ™ 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


Gökhan

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.

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

I use the code from the RectangleSelector class help with your suggested code. I know that I have to update y-axis accordingly to x values such that their positions and sizes must much so that I can plot them in a new plot. And I know that the answer lies in a mask; I have to create a mask from x_new and apply it to y. Do you have any hint on this?

Another point is do you have any idea how to save values from inside onselect action?

For some reason my ipython session doesn’t remember values after I run the given script:

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       
xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
x_new = x[(x>= xmin) & (x <= xmax)]
#mask = [x == x_new[i] for i in range(len(x_new))]
#print mask
#print len(x_new)
#print len(y_new)
#fig_new = figure()
#plot(x_new, y_new)
#fig_new.show()

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=‘box’)
connect(‘key_press_event’, toggle_selector)
show()

Gökhan

···

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler <MatthiasMichler@…361…> wrote:

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 ™ 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

Hi Gökhan,

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

I use the code from the RectangleSelector class help with your suggested
code. I know that I have to update y-axis accordingly to x values such that
their positions and sizes must much so that I can plot them in a new plot.
And I know that the answer lies in a mask; I have to create a mask from
x_new and apply it to y. Do you have any hint on this?

Unfortunately I'm not familiar with numpy masks, but what I would do is:

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
# indices inside x-range
indices = (x>= xmin) & (x <= xmax)
# OR: indices for data inside the selected rectangle
#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)
xnew = x[indices]
ynew = y[indices]

Another point is do you have any idea how to save values from inside
onselect action?

What do you mean by saving?
Saving to disk?
# for ascii format I use:
from scipy.io import write_array

# for numpy arrays you can use
import numpy as np
a = np.arange(10)
a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the module
matplotlib.mlab, which also allows reading different types of formatted data.

If you think of saving inside the program. You need a global variable
(statement "global x" at the beginning of onselect) otherwise all variables
are deleted at the end of each onselect call.

For some reason my ipython session doesn't remember values after I run the
given script:

see three lines above, please.

best regards Matthias

···

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

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
    xmin = min(eclick.xdata, erelease.xdata)
    xmax = max(eclick.xdata, erelease.xdata)
    ymin = min(eclick.ydata, erelease.ydata)
    ymax = max(eclick.ydata, erelease.ydata)
    x_new = x[(x>= xmin) & (x <= xmax)]
    #mask = [x == x_new[i] for i in range(len(x_new))]
    #print mask
    #print len(x_new)
    #print len(y_new)
    #fig_new = figure()
    #plot(x_new, y_new)
    #fig_new.show()

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='box')
connect('key_press_event', toggle_selector)
show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > <MatthiasMichler@...361...>wrote:
> 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.htm
>l). 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
> matplotlib-users List Signup and Options

Matthias Michler wrote:

Hi Gökhan,

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

You might also find useful ideas here:

http://currents.soest.hawaii.edu/hg/hgwebdir.cgi/pycurrents/file/2ec7845a90c3/plot/txyzoom.py#l1

I haven't followed this thread closely, but my impression is that what you are trying to do is similar to, but perhaps simpler than, what is done by txyzoom.py.

I don't have license info in the file or repo yet, but consider it available under a matplotlib-style license.

Eric

···

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

I use the code from the RectangleSelector class help with your suggested
code. I know that I have to update y-axis accordingly to x values such that
their positions and sizes must much so that I can plot them in a new plot.
And I know that the answer lies in a mask; I have to create a mask from
x_new and apply it to y. Do you have any hint on this?

Unfortunately I'm not familiar with numpy masks, but what I would do is:

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
# indices inside x-range
indices = (x>= xmin) & (x <= xmax)
# OR: indices for data inside the selected rectangle
#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)
xnew = x[indices]
ynew = y[indices]

Another point is do you have any idea how to save values from inside
onselect action?

What do you mean by saving?
Saving to disk? # for ascii format I use:
from scipy.io import write_array

# for numpy arrays you can use
import numpy as np
a = np.arange(10)
a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the module matplotlib.mlab, which also allows reading different types of formatted data.

If you think of saving inside the program. You need a global variable (statement "global x" at the beginning of onselect) otherwise all variables are deleted at the end of each onselect call.

For some reason my ipython session doesn't remember values after I run the
given script:

see three lines above, please.

best regards Matthias

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
    xmin = min(eclick.xdata, erelease.xdata)
    xmax = max(eclick.xdata, erelease.xdata)
    ymin = min(eclick.ydata, erelease.ydata)
    ymax = max(eclick.ydata, erelease.ydata)
    x_new = x[(x>= xmin) & (x <= xmax)]
    #mask = [x == x_new[i] for i in range(len(x_new))]
    #print mask
    #print len(x_new)
    #print len(y_new)
    #fig_new = figure()
    #plot(x_new, y_new)
    #fig_new.show()

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='box')
connect('key_press_event', toggle_selector)
show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler >> >> <MatthiasMichler@...361...>wrote:

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.htm
l). 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
matplotlib-users List Signup and Options

------------------------------------------------------------------------------
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
matplotlib-users List Signup and Options

Thanks for elegant trick Matthias.

I have modified onselect function following your suggestions, and it is working as I wanted it to be. Select a portion and get a zoomed view in a new figure.

def onselect(eclick, erelease):
# eclick and erelease are matplotlib events at press and release
global x_new
global y_new
print ’ startposition : (%f, %f)’ % (eclick.xdata, eclick.ydata)
print ’ endposition : (%f, %f)’ % (erelease.xdata, erelease.ydata)
print ’ used button : ', eclick.button
xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
indices = (x >= xmin) & (x <= xmax) & (y >= ymin) & (y <= ymax)
x_new = x[indices]
y_new = y[indices]
fig_new = figure()
plot(x_new, y_new)
fig_new.show()

There is still a minute point, that I would like mention again. Even though I used global style variables I can’t still see them when I quit the program.

What I do is run the file within IPython by run command. In my case the file is ‘rect.py.’ and I do run rect.py. When I quit and do whos querry, I can’t see global x_new nor y_new at the resulting lines:

In [13]: whos
Variable Type Data/Info

···

RectangleSelector classobj matplotlib.widgets.RectangleSelector
ax AxesSubplot Axes(0.125,0.1;0.775x0.8)
fig function <function figure at 0xa752c6c>
onselect function <function onselect at 0xac0ec34>
toggle_selector function <function toggle_selector at 0xac0ef0c>
x ndarray 100: 100 elems, type float64, 800 bytes
y ndarray 100: 100 elems, type float64, 800 bytes

For the masking, I was planning to use a masking scheme as given below. Let say I have an array which “a”

In [14]: a = arange(5)

In [15]: a
Out[15]: array([0, 1, 2, 3, 4])

and my secondary array is “b”

In [16]: b = array([2,3])

What I want to do is to mask a with b values and get an array of:

[array([False, False, True, True, False], dtype=bool)]

That is just an manually created array. I still don’t know how to do this programmatically in Pythonic fashion.

Again thanks for your help.

Gökhan

On Mon, Apr 20, 2009 at 4:09 AM, Matthias Michler <MatthiasMichler@…361…> wrote:

Hi Gökhan,

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

I use the code from the RectangleSelector class help with your suggested

code. I know that I have to update y-axis accordingly to x values such that

their positions and sizes must much so that I can plot them in a new plot.

And I know that the answer lies in a mask; I have to create a mask from

x_new and apply it to y. Do you have any hint on this?

Unfortunately I’m not familiar with numpy masks, but what I would do is:

xmin = min(eclick.xdata, erelease.xdata)

xmax = max(eclick.xdata, erelease.xdata)

ymin = min(eclick.ydata, erelease.ydata)

ymax = max(eclick.ydata, erelease.ydata)

indices inside x-range

indices = (x>= xmin) & (x <= xmax)

OR: indices for data inside the selected rectangle

#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)

xnew = x[indices]

ynew = y[indices]

Another point is do you have any idea how to save values from inside

onselect action?

What do you mean by saving?

Saving to disk?

for ascii format I use:

from scipy.io import write_array

for numpy arrays you can use

import numpy as np

a = np.arange(10)

a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the module

matplotlib.mlab, which also allows reading different types of formatted data.

If you think of saving inside the program. You need a global variable

(statement “global x” at the beginning of onselect) otherwise all variables

are deleted at the end of each onselect call.

For some reason my ipython session doesn’t remember values after I run the

given script:

see three lines above, please.

best regards Matthias

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
xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
x_new = x[(x>= xmin) & (x <= xmax)]
#mask = [x == x_new[i] for i in range(len(x_new))]
#print mask
#print len(x_new)
#print len(y_new)
#fig_new = figure()
#plot(x_new, y_new)
#fig_new.show()

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=‘box’)

connect(‘key_press_event’, toggle_selector)

show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > > > > > <MatthiasMichler@…2559…1…>wrote:

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.htm

l). 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 ™ 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


Stay on top of everything new and different, both inside and

around Java ™ 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

Eric,

As you said, your program features more than what me in my mind. It looks very cool. There are some parts which I don’t understand quite well.

I will definitely save it for my future programming adventures. I will solely use it in my academical research, since I am a graduate student working on atmospheric sciences.

I like the Mercurial repository of the project, and the way it is presented. I am planning establish something similar to yours. So in the future I might have some more questions to you.

By the way, could please tell me more what does pycurrents do? I can guess a little from its name. Actually for the next year I have a plan of implementing a design named pyclouds for simple cloud simulation and/or modelling.

Gökhan

···

On Mon, Apr 20, 2009 at 1:29 PM, Eric Firing <efiring@…83…202…> wrote:

Matthias Michler wrote:

Hi Gökhan,

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

You might also find useful ideas here:

http://currents.soest.hawaii.edu/hg/hgwebdir.cgi/pycurrents/file/2ec7845a90c3/plot/txyzoom.py#l1

I haven’t followed this thread closely, but my impression is that what

you are trying to do is similar to, but perhaps simpler than, what is

done by txyzoom.py.

I don’t have license info in the file or repo yet, but consider it

available under a matplotlib-style license.

Eric

I use the code from the RectangleSelector class help with your suggested

code. I know that I have to update y-axis accordingly to x values such that

their positions and sizes must much so that I can plot them in a new plot.

And I know that the answer lies in a mask; I have to create a mask from

x_new and apply it to y. Do you have any hint on this?

Unfortunately I’m not familiar with numpy masks, but what I would do is:

xmin = min(eclick.xdata, erelease.xdata)

xmax = max(eclick.xdata, erelease.xdata)

ymin = min(eclick.ydata, erelease.ydata)

ymax = max(eclick.ydata, erelease.ydata)

indices inside x-range

indices = (x>= xmin) & (x <= xmax)

OR: indices for data inside the selected rectangle

#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)

xnew = x[indices]

ynew = y[indices]

Another point is do you have any idea how to save values from inside

onselect action?

What do you mean by saving?

Saving to disk?

for ascii format I use:

from scipy.io import write_array

for numpy arrays you can use

import numpy as np

a = np.arange(10)

a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the module

matplotlib.mlab, which also allows reading different types of formatted data.

If you think of saving inside the program. You need a global variable

(statement “global x” at the beginning of onselect) otherwise all variables

are deleted at the end of each onselect call.

For some reason my ipython session doesn’t remember values after I run the

given script:

see three lines above, please.

best regards Matthias

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
xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
x_new = x[(x>= xmin) & (x <= xmax)]
#mask = [x == x_new[i] for i in range(len(x_new))]
#print mask
#print len(x_new)
#print len(y_new)
#fig_new = figure()
#plot(x_new, y_new)
#fig_new.show()

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=‘box’)

connect(‘key_press_event’, toggle_selector)

show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > >> > > >> <MatthiasMichler@…120…361…>wrote:

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.htm

l). 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 ™ 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


Stay on top of everything new and different, both inside and

around Java ™ 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


Stay on top of everything new and different, both inside and

around Java ™ 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

Gökhan SEVER wrote:

Eric,

As you said, your program features more than what me in my mind. It looks very cool. There are some parts which I don't understand quite well.

I will definitely save it for my future programming adventures. I will solely use it in my academical research, since I am a graduate student working on atmospheric sciences.

I like the Mercurial repository of the project, and the way it is presented. I am planning establish something similar to yours. So in the future I might have some more questions to you.

By the way, could please tell me more what does pycurrents do? I can guess a little from its name. Actually for the next year I have a plan of implementing a design named pyclouds for simple cloud simulation and/or modelling.

Gökhan

Gökhan,

pycurrents is simply a name for one of several repos into which we have divided our code; it is for python code that we use for our work in physical oceanography, with a heavy weighting toward processing acoustic Doppler current profiler (ADCP) data. It is a catch-all. It includes good stuff, work in progress (to some extent that description applies to everything), and some things that are obsolete and/or first tries still waiting to be rewritten. For context, see http://currents.soest.hawaii.edu/.

Eric

Eric,

I see many quality descriptive plots and analysis results following the main currents page. Really a professional looking research job. Could you please tell me how many people working on this project and how long have you been working on it?

Thank you

Gökhan

···

On Mon, Apr 20, 2009 at 5:18 PM, Eric Firing <efiring@…83…202…> wrote:

Gökhan SEVER wrote:

Eric,

As you said, your program features more than what me in my mind. It looks very cool. There are some parts which I don’t understand quite well.

I will definitely save it for my future programming adventures. I will solely use it in my academical research, since I am a graduate student working on atmospheric sciences.

I like the Mercurial repository of the project, and the way it is presented. I am planning establish something similar to yours. So in the future I might have some more questions to you.

By the way, could please tell me more what does pycurrents do? I can guess a little from its name. Actually for the next year I have a plan of implementing a design named pyclouds for simple cloud simulation and/or modelling.

Gökhan

Gökhan,

pycurrents is simply a name for one of several repos into which we have divided our code; it is for python code that we use for our work in physical oceanography, with a heavy weighting toward processing acoustic Doppler current profiler (ADCP) data. It is a catch-all. It includes good stuff, work in progress (to some extent that description applies to everything), and some things that are obsolete and/or first tries still waiting to be rewritten. For context, see http://currents.soest.hawaii.edu/.

Eric

Gökhan SEVER wrote:

Eric,

I see many quality descriptive plots and analysis results following the main currents page. Really a professional looking research job. Could you please tell me how many people working on this project and how long have you been working on it?

We are way off topic here, so I will end this thread to the list and reply to you individually.

Eric

Hi Gökhan,
Hi list,
Hi experts on masked arrays,

I run the attached script (copied from your last two emails) and I can use
x_new, y_new after closing the figures (where x_new and y_new are the values
selected in the last selection).

I don't know, what is going wrong with your script on your system.

### my output ##########################
In [1]: run rect.py
startposition : (0.276210, 0.592969)
endposition : (0.542339, 0.309375)
used button : 1
startposition : (0.745968, 0.747656)
endposition : (0.745968, 0.747656)
used button : 1
startposition : (0.645161, 0.761719)
endposition : (0.806452, 0.609375)
used button : 3
startposition : (0.808468, 0.607031)
endposition : (0.808468, 0.604688)
used button : 3
startposition : (0.086694, 0.166406)
endposition : (0.137097, 0.070313)
used button : 1
startposition : (0.921371, 0.850781)
endposition : (0.987903, 0.728906)
used button : 1

In [2]: x_new
Out[2]:
array([ 0.92929293, 0.93939394, 0.94949495, 0.95959596, 0.96969697,
        0.97979798])

In [3]: y_new
Out[3]:
array([ 0.80119703, 0.8072005 , 0.81312162, 0.81895978, 0.82471437,
        0.83038482])

In [4]:

rect.py (1.29 KB)

···

#############

Please see my comments below.

On Monday 20 April 2009 23:16:37 Gökhan SEVER wrote:

Thanks for elegant trick Matthias.

I have modified onselect function following your suggestions, and it is
working as I wanted it to be. Select a portion and get a zoomed view in a
new figure.

def onselect(eclick, erelease):
    # eclick and erelease are matplotlib events at press and release
    global x_new
    global y_new
    print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
    print ' endposition : (%f, %f)' % (erelease.xdata, erelease.ydata)
    print ' used button : ', eclick.button
    xmin = min(eclick.xdata, erelease.xdata)
    xmax = max(eclick.xdata, erelease.xdata)
    ymin = min(eclick.ydata, erelease.ydata)
    ymax = max(eclick.ydata, erelease.ydata)
    indices = (x >= xmin) & (x <= xmax) & (y >= ymin) & (y <= ymax)
    x_new = x[indices]
    y_new = y[indices]
    fig_new = figure()
    plot(x_new, y_new)
    fig_new.show()

There is still a minute point, that I would like mention again. Even though
I used global style variables I can't still see them when I quit the
program.

What I do is run the file within IPython by run command. In my case the
file is 'rect.py.' and I do run rect.py. When I quit and do whos querry, I
can't see global x_new nor y_new at the resulting lines:

In [13]: whos
Variable Type Data/Info
--------------------------------------------
RectangleSelector classobj matplotlib.widgets.RectangleSelector
ax AxesSubplot Axes(0.125,0.1;0.775x0.8)
fig function <function figure at 0xa752c6c>
onselect function <function onselect at 0xac0ec34>
toggle_selector function <function toggle_selector at 0xac0ef0c>
x ndarray 100: 100 elems, type `float64`, 800
bytes y ndarray 100: 100 elems, type `float64`,
800 bytes

For the masking, I was planning to use a masking scheme as given below. Let
say I have an array which "a"

In [14]: a = arange(5)

In [15]: a
Out[15]: array([0, 1, 2, 3, 4])

and my secondary array is "b"

In [16]: b = array([2,3])

What I want to do is to mask a with b values and get an array of:

[array([False, False, True, True, False], dtype=bool)]

That is just an manually created array. I still don't know how to do this
programmatically in Pythonic fashion.

As I mentioned before I'm not familiar with numpys masked arrays. In this list
I read several comments on them, but I never used them. But I think they are
what you are after. Maybe someone else can give you a hint or you try numpys
online documentation.
All I could provide is again a little manually work using a for-loop. So
something like

mask = zeros(len(a), dtype=bool)
for index in xrange(len(a)): # run through array a
    if a[index] in b:
        mask[index] = True
print mask # gives array([False, False, True, True, False], dtype=bool)

Furthermore I'm not a Python expert and therefore I'm not the guy to ask for
programing in "Pythonic fashion". Maybe some else can give a comment?

best regards Matthias

Again thanks for your help.

Gökhan

On Mon, Apr 20, 2009 at 4:09 AM, Matthias Michler > > <MatthiasMichler@...361...>wrote:
> Hi Gökhan,
>
> On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:
> > Thanks for the pointer Matthias,
> >
> > That is exactly what I have been looking for.
> >
> > I use the code from the RectangleSelector class help with your
> > suggested code. I know that I have to update y-axis accordingly to x
> > values such
>
> that
>
> > their positions and sizes must much so that I can plot them in a new
>
> plot.
>
> > And I know that the answer lies in a mask; I have to create a mask from
> > x_new and apply it to y. Do you have any hint on this?
>
> Unfortunately I'm not familiar with numpy masks, but what I would do is:
>
> xmin = min(eclick.xdata, erelease.xdata)
> xmax = max(eclick.xdata, erelease.xdata)
> ymin = min(eclick.ydata, erelease.ydata)
> ymax = max(eclick.ydata, erelease.ydata)
> # indices inside x-range
> indices = (x>= xmin) & (x <= xmax)
> # OR: indices for data inside the selected rectangle
> #indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)
> xnew = x[indices]
> ynew = y[indices]
>
> > Another point is do you have any idea how to save values from inside
> > onselect action?
>
> What do you mean by saving?
> Saving to disk?
> # for ascii format I use:
> from scipy.io import write_array
>
> # for numpy arrays you can use
> import numpy as np
> a = np.arange(10)
> a.tofile # Write array to a file as text or binary.
>
> and I think there is also some Matplotlib function for this. In the
> module matplotlib.mlab, which also allows reading different types of
> formatted data.
>
> If you think of saving inside the program. You need a global variable
> (statement "global x" at the beginning of onselect) otherwise all
> variables are deleted at the end of each onselect call.
>
> > For some reason my ipython session doesn't remember values after I run
>
> the
>
> > given script:
>
> see three lines above, please.
>
> best regards Matthias
>
> > 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
> > xmin = min(eclick.xdata, erelease.xdata)
> > xmax = max(eclick.xdata, erelease.xdata)
> > ymin = min(eclick.ydata, erelease.ydata)
> > ymax = max(eclick.ydata, erelease.ydata)
> > x_new = x[(x>= xmin) & (x <= xmax)]
> > #mask = [x == x_new[i] for i in range(len(x_new))]
> > #print mask
> > #print len(x_new)
> > #print len(y_new)
> > #fig_new = figure()
> > #plot(x_new, y_new)
> > #fig_new.show()
> >
> > 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='box')
> > connect('key_press_event', toggle_selector)
> > show()
> >
> > Gökhan
> >
> >
> > On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > > > > > <MatthiasMichler@...361...>wrote:
> > > 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.htm
>
> > >l). 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
> > > matplotlib-users List Signup and Options
>
> -------------------------------------------------------------------------
>----- 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
> matplotlib-users List Signup and Options

Hi Matthias,

Thanks for your reply again. Unfortunately I can’t read x_new or y_new after I kill the figures (nor when they are active). I don’t know what exactly wrong in my configuration or IPython. I use IPython 0.10.bzr.r1163 on Fedora 10.

Hopefully, I will solve the masked array riddle by reading more (although haven’t seen a specific example similar to my question on the numpy reference pages), if not getting some insight from a numpy expert or like you said from an expert on masked arrays :slight_smile:

Have a good Tuesday to all.

Gökhan

···

On Tue, Apr 21, 2009 at 3:21 AM, Matthias Michler <MatthiasMichler@…361…> wrote:

Hi Gökhan,

Hi list,

Hi experts on masked arrays,

I run the attached script (copied from your last two emails) and I can use

x_new, y_new after closing the figures (where x_new and y_new are the values

selected in the last selection).

I don’t know, what is going wrong with your script on your system.

my output

In [1]: run rect.py

startposition : (0.276210, 0.592969)

endposition : (0.542339, 0.309375)

used button : 1

startposition : (0.745968, 0.747656)

endposition : (0.745968, 0.747656)

used button : 1

startposition : (0.645161, 0.761719)

endposition : (0.806452, 0.609375)

used button : 3

startposition : (0.808468, 0.607031)

endposition : (0.808468, 0.604688)

used button : 3

startposition : (0.086694, 0.166406)

endposition : (0.137097, 0.070313)

used button : 1

startposition : (0.921371, 0.850781)

endposition : (0.987903, 0.728906)

used button : 1

In [2]: x_new

Out[2]:

array([ 0.92929293, 0.93939394, 0.94949495, 0.95959596, 0.96969697,

    0.97979798])

In [3]: y_new

Out[3]:

array([ 0.80119703, 0.8072005 , 0.81312162, 0.81895978, 0.82471437,

    0.83038482])

In [4]:

#############

Please see my comments below.

On Monday 20 April 2009 23:16:37 Gökhan SEVER wrote:

Thanks for elegant trick Matthias.

I have modified onselect function following your suggestions, and it is

working as I wanted it to be. Select a portion and get a zoomed view in a

new figure.

def onselect(eclick, erelease):

# eclick and erelease are matplotlib events at press and release
global x_new
global y_new
print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
print ' endposition   : (%f, %f)' % (erelease.xdata, erelease.ydata)
print ' used button   : ', eclick.button
xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
indices = (x >= xmin) & (x <= xmax) & (y >= ymin) & (y <= ymax)
x_new = x[indices]
y_new = y[indices]
fig_new = figure()
plot(x_new, y_new)
fig_new.show()

There is still a minute point, that I would like mention again. Even though

I used global style variables I can’t still see them when I quit the

program.

What I do is run the file within IPython by run command. In my case the

file is ‘rect.py.’ and I do run rect.py. When I quit and do whos querry, I

can’t see global x_new nor y_new at the resulting lines:

In [13]: whos

Variable Type Data/Info


RectangleSelector classobj matplotlib.widgets.RectangleSelector

ax AxesSubplot Axes(0.125,0.1;0.775x0.8)

fig function <function figure at 0xa752c6c>

onselect function <function onselect at 0xac0ec34>

toggle_selector function <function toggle_selector at 0xac0ef0c>

x ndarray 100: 100 elems, type float64, 800

bytes y ndarray 100: 100 elems, type float64,

800 bytes

For the masking, I was planning to use a masking scheme as given below. Let

say I have an array which “a”

In [14]: a = arange(5)

In [15]: a

Out[15]: array([0, 1, 2, 3, 4])

and my secondary array is “b”

In [16]: b = array([2,3])

What I want to do is to mask a with b values and get an array of:

[array([False, False, True, True, False], dtype=bool)]

That is just an manually created array. I still don’t know how to do this

programmatically in Pythonic fashion.

As I mentioned before I’m not familiar with numpys masked arrays. In this list

I read several comments on them, but I never used them. But I think they are

what you are after. Maybe someone else can give you a hint or you try numpys

online documentation.

All I could provide is again a little manually work using a for-loop. So

something like

mask = zeros(len(a), dtype=bool)

for index in xrange(len(a)): # run through array a

if a[index] in b:

    mask[index] = True

print mask # gives array([False, False, True, True, False], dtype=bool)

Furthermore I’m not a Python expert and therefore I’m not the guy to ask for

programing in “Pythonic fashion”. Maybe some else can give a comment?

best regards Matthias

Again thanks for your help.

Gökhan

On Mon, Apr 20, 2009 at 4:09 AM, Matthias Michler > > > > > > <MatthiasMichler@…2559…1…>wrote:

Hi Gökhan,

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

I use the code from the RectangleSelector class help with your

suggested code. I know that I have to update y-axis accordingly to x

values such

that

their positions and sizes must much so that I can plot them in a new

plot.

And I know that the answer lies in a mask; I have to create a mask from

x_new and apply it to y. Do you have any hint on this?

Unfortunately I’m not familiar with numpy masks, but what I would do is:

xmin = min(eclick.xdata, erelease.xdata)

xmax = max(eclick.xdata, erelease.xdata)

ymin = min(eclick.ydata, erelease.ydata)

ymax = max(eclick.ydata, erelease.ydata)

indices inside x-range

indices = (x>= xmin) & (x <= xmax)

OR: indices for data inside the selected rectangle

#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)

xnew = x[indices]

ynew = y[indices]

Another point is do you have any idea how to save values from inside

onselect action?

What do you mean by saving?

Saving to disk?

for ascii format I use:

from scipy.io import write_array

for numpy arrays you can use

import numpy as np

a = np.arange(10)

a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the

module matplotlib.mlab, which also allows reading different types of

formatted data.

If you think of saving inside the program. You need a global variable

(statement “global x” at the beginning of onselect) otherwise all

variables are deleted at the end of each onselect call.

For some reason my ipython session doesn’t remember values after I run

the

given script:

see three lines above, please.

best regards Matthias

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

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
x_new = x[(x>= xmin) & (x <= xmax)]
#mask = [x == x_new[i] for i in range(len(x_new))]
#print mask
#print len(x_new)
#print len(y_new)
#fig_new = figure()
#plot(x_new, y_new)
#fig_new.show()

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=‘box’)

connect(‘key_press_event’, toggle_selector)

show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > > > > > > > > > <MatthiasMichler@…361…>wrote:

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.htm

l). 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 ™ 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


----- Stay on top of everything new and different, both inside and

around Java ™ 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


Stay on top of everything new and different, both inside and

around Java ™ 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

Hi Gökhan,
Hi list,

Hi Matthias,

Thanks for your reply again. Unfortunately I can't read x_new or y_new
after I kill the figures (nor when they are active). I don't know what
exactly wrong in my configuration or IPython. I use IPython 0.10.bzr.r1163
on Fedora 10.

With "kill" you mean just closing the figures with button "X", isn't it?

What about adding the line
print x_new, y_new
after the show() in your rect.py-script? Does this give some output in ipython
or if you run the script using "python rect.py" ?

best regards
Matthias

···

On Tuesday 21 April 2009 19:44:18 Gökhan SEVER wrote:

Hopefully, I will solve the masked array riddle by reading more (although
haven't seen a specific example similar to my question on the numpy
reference pages), if not getting some insight from a numpy expert or like
you said from an expert on masked arrays :slight_smile:

Have a good Tuesday to all.

Gökhan

On Tue, Apr 21, 2009 at 3:21 AM, Matthias Michler > > <MatthiasMichler@...361...>wrote:
> Hi Gökhan,
> Hi list,
> Hi experts on masked arrays,
>
> I run the attached script (copied from your last two emails) and I can
> use x_new, y_new after closing the figures (where x_new and y_new are the
> values
> selected in the last selection).
>
> I don't know, what is going wrong with your script on your system.
>
> ### my output ##########################
> In [1]: run rect.py
> startposition : (0.276210, 0.592969)
> endposition : (0.542339, 0.309375)
> used button : 1
> startposition : (0.745968, 0.747656)
> endposition : (0.745968, 0.747656)
> used button : 1
> startposition : (0.645161, 0.761719)
> endposition : (0.806452, 0.609375)
> used button : 3
> startposition : (0.808468, 0.607031)
> endposition : (0.808468, 0.604688)
> used button : 3
> startposition : (0.086694, 0.166406)
> endposition : (0.137097, 0.070313)
> used button : 1
> startposition : (0.921371, 0.850781)
> endposition : (0.987903, 0.728906)
> used button : 1
>
> In [2]: x_new
> Out[2]:
> array([ 0.92929293, 0.93939394, 0.94949495, 0.95959596, 0.96969697,
> 0.97979798])
>
> In [3]: y_new
> Out[3]:
> array([ 0.80119703, 0.8072005 , 0.81312162, 0.81895978, 0.82471437,
> 0.83038482])
>
> In [4]:
> #############
>
> Please see my comments below.
>
> On Monday 20 April 2009 23:16:37 Gökhan SEVER wrote:
> > Thanks for elegant trick Matthias.
> >
> > I have modified onselect function following your suggestions, and it is
> > working as I wanted it to be. Select a portion and get a zoomed view in
> > a new figure.
> >
> > def onselect(eclick, erelease):
> > # eclick and erelease are matplotlib events at press and release
> > global x_new
> > global y_new
> > print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
> > print ' endposition : (%f, %f)' % (erelease.xdata,
> > erelease.ydata) print ' used button : ', eclick.button
> > xmin = min(eclick.xdata, erelease.xdata)
> > xmax = max(eclick.xdata, erelease.xdata)
> > ymin = min(eclick.ydata, erelease.ydata)
> > ymax = max(eclick.ydata, erelease.ydata)
> > indices = (x >= xmin) & (x <= xmax) & (y >= ymin) & (y <= ymax)
> > x_new = x[indices]
> > y_new = y[indices]
> > fig_new = figure()
> > plot(x_new, y_new)
> > fig_new.show()
> >
> > There is still a minute point, that I would like mention again. Even
>
> though
>
> > I used global style variables I can't still see them when I quit the
> > program.
> >
> > What I do is run the file within IPython by run command. In my case the
> > file is 'rect.py.' and I do run rect.py. When I quit and do whos
> > querry,
>
> I
>
> > can't see global x_new nor y_new at the resulting lines:
> >
> > In [13]: whos
> > Variable Type Data/Info
> > --------------------------------------------
> > RectangleSelector classobj matplotlib.widgets.RectangleSelector
> > ax AxesSubplot Axes(0.125,0.1;0.775x0.8)
> > fig function <function figure at 0xa752c6c>
> > onselect function <function onselect at 0xac0ec34>
> > toggle_selector function <function toggle_selector at
>
> 0xac0ef0c>
>
> > x ndarray 100: 100 elems, type `float64`, 800
> > bytes y ndarray 100: 100 elems, type
> > `float64`, 800 bytes
> >
> >
> > For the masking, I was planning to use a masking scheme as given below.
>
> Let
>
> > say I have an array which "a"
> >
> > In [14]: a = arange(5)
> >
> > In [15]: a
> > Out[15]: array([0, 1, 2, 3, 4])
> >
> > and my secondary array is "b"
> >
> > In [16]: b = array([2,3])
> >
> > What I want to do is to mask a with b values and get an array of:
> >
> > [array([False, False, True, True, False], dtype=bool)]
> >
> > That is just an manually created array. I still don't know how to do
> > this programmatically in Pythonic fashion.
>
> As I mentioned before I'm not familiar with numpys masked arrays. In this
> list
> I read several comments on them, but I never used them. But I think they
> are
> what you are after. Maybe someone else can give you a hint or you try
> numpys
> online documentation.
> All I could provide is again a little manually work using a for-loop. So
> something like
>
> mask = zeros(len(a), dtype=bool)
> for index in xrange(len(a)): # run through array a
> if a[index] in b:
> mask[index] = True
> print mask # gives array([False, False, True, True, False],
> dtype=bool)
>
> Furthermore I'm not a Python expert and therefore I'm not the guy to ask
> for
> programing in "Pythonic fashion". Maybe some else can give a comment?
>
> best regards Matthias
>
> > Again thanks for your help.
> >
> > Gökhan
> >
> >
> > On Mon, Apr 20, 2009 at 4:09 AM, Matthias Michler > > > > > > <MatthiasMichler@...361...>wrote:
> > > Hi Gökhan,
> > >
> > > On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:
> > > > Thanks for the pointer Matthias,
> > > >
> > > > That is exactly what I have been looking for.
> > > >
> > > > I use the code from the RectangleSelector class help with your
> > > > suggested code. I know that I have to update y-axis accordingly to
> > > > x values such
> > >
> > > that
> > >
> > > > their positions and sizes must much so that I can plot them in a
> > > > new
> > >
> > > plot.
> > >
> > > > And I know that the answer lies in a mask; I have to create a mask
>
> from
>
> > > > x_new and apply it to y. Do you have any hint on this?
> > >
> > > Unfortunately I'm not familiar with numpy masks, but what I would do
>
> is:
> > > xmin = min(eclick.xdata, erelease.xdata)
> > > xmax = max(eclick.xdata, erelease.xdata)
> > > ymin = min(eclick.ydata, erelease.ydata)
> > > ymax = max(eclick.ydata, erelease.ydata)
> > > # indices inside x-range
> > > indices = (x>= xmin) & (x <= xmax)
> > > # OR: indices for data inside the selected rectangle
> > > #indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)
> > > xnew = x[indices]
> > > ynew = y[indices]
> > >
> > > > Another point is do you have any idea how to save values from
> > > > inside onselect action?
> > >
> > > What do you mean by saving?
> > > Saving to disk?
> > > # for ascii format I use:
> > > from scipy.io import write_array
> > >
> > > # for numpy arrays you can use
> > > import numpy as np
> > > a = np.arange(10)
> > > a.tofile # Write array to a file as text or binary.
> > >
> > > and I think there is also some Matplotlib function for this. In the
> > > module matplotlib.mlab, which also allows reading different types of
> > > formatted data.
> > >
> > > If you think of saving inside the program. You need a global variable
> > > (statement "global x" at the beginning of onselect) otherwise all
> > > variables are deleted at the end of each onselect call.
> > >
> > > > For some reason my ipython session doesn't remember values after I
>
> run
>
> > > the
> > >
> > > > given script:
> > >
> > > see three lines above, please.
> > >
> > > best regards Matthias
> > >
> > > > 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
> > > > xmin = min(eclick.xdata, erelease.xdata)
> > > > xmax = max(eclick.xdata, erelease.xdata)
> > > > ymin = min(eclick.ydata, erelease.ydata)
> > > > ymax = max(eclick.ydata, erelease.ydata)
> > > > x_new = x[(x>= xmin) & (x <= xmax)]
> > > > #mask = [x == x_new[i] for i in range(len(x_new))]
> > > > #print mask
> > > > #print len(x_new)
> > > > #print len(y_new)
> > > > #fig_new = figure()
> > > > #plot(x_new, y_new)
> > > > #fig_new.show()
> > > >
> > > > 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='box') connect('key_press_event', toggle_selector)
> > > > show()
> > > >
> > > > Gökhan
> > > >
> > > >
> > > > On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > > > > > > > > > <MatthiasMichler@...361...>wrote:
> > > > > 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.htm
>
> > > > >l). 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.

Huh,

My definition of kill is just like you said.

Inside Ipython print statements output x_new, and y_new values, but no context saving :frowning:

Worse thing is python rect.py does not nothing, not even with -d switch :frowning: :frowning:

I will try with Ipython 0.9.1.

Gökhan

···

On Wed, Apr 22, 2009 at 4:40 AM, Matthias Michler <MatthiasMichler@…361…> wrote:

Hi Gökhan,

Hi list,

On Tuesday 21 April 2009 19:44:18 Gökhan SEVER wrote:

Hi Matthias,

Thanks for your reply again. Unfortunately I can’t read x_new or y_new

after I kill the figures (nor when they are active). I don’t know what

exactly wrong in my configuration or IPython. I use IPython 0.10.bzr.r1163

on Fedora 10.

With “kill” you mean just closing the figures with button “X”, isn’t it?

What about adding the line

print x_new, y_new

after the show() in your rect.py-script? Does this give some output in ipython

or if you run the script using “python rect.py” ?

best regards

Matthias

Hopefully, I will solve the masked array riddle by reading more (although

haven’t seen a specific example similar to my question on the numpy

reference pages), if not getting some insight from a numpy expert or like

you said from an expert on masked arrays :slight_smile:

Have a good Tuesday to all.

Gökhan

On Tue, Apr 21, 2009 at 3:21 AM, Matthias Michler > > > > > > <MatthiasMichler@…2559…1…>wrote:

Hi Gökhan,

Hi list,

Hi experts on masked arrays,

I run the attached script (copied from your last two emails) and I can

use x_new, y_new after closing the figures (where x_new and y_new are the

values

selected in the last selection).

I don’t know, what is going wrong with your script on your system.

my output

In [1]: run rect.py

startposition : (0.276210, 0.592969)

endposition : (0.542339, 0.309375)

used button : 1

startposition : (0.745968, 0.747656)

endposition : (0.745968, 0.747656)

used button : 1

startposition : (0.645161, 0.761719)

endposition : (0.806452, 0.609375)

used button : 3

startposition : (0.808468, 0.607031)

endposition : (0.808468, 0.604688)

used button : 3

startposition : (0.086694, 0.166406)

endposition : (0.137097, 0.070313)

used button : 1

startposition : (0.921371, 0.850781)

endposition : (0.987903, 0.728906)

used button : 1

In [2]: x_new

Out[2]:

array([ 0.92929293, 0.93939394, 0.94949495, 0.95959596, 0.96969697,

   0.97979798])

In [3]: y_new

Out[3]:

array([ 0.80119703, 0.8072005 , 0.81312162, 0.81895978, 0.82471437,

   0.83038482])

In [4]:

#############

Please see my comments below.

On Monday 20 April 2009 23:16:37 Gökhan SEVER wrote:

Thanks for elegant trick Matthias.

I have modified onselect function following your suggestions, and it is

working as I wanted it to be. Select a portion and get a zoomed view in

a new figure.

def onselect(eclick, erelease):

# eclick and erelease are matplotlib events at press and release
global x_new
global y_new
print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
print ' endposition   : (%f, %f)' % (erelease.xdata,

erelease.ydata) print ’ used button : ', eclick.button

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
indices = (x >= xmin) & (x <= xmax) & (y >= ymin) & (y <= ymax)
x_new = x[indices]
y_new = y[indices]
fig_new = figure()
plot(x_new, y_new)
fig_new.show()

There is still a minute point, that I would like mention again. Even

though

I used global style variables I can’t still see them when I quit the

program.

What I do is run the file within IPython by run command. In my case the

file is ‘rect.py.’ and I do run rect.py. When I quit and do whos

querry,

I

can’t see global x_new nor y_new at the resulting lines:

In [13]: whos

Variable Type Data/Info


RectangleSelector classobj matplotlib.widgets.RectangleSelector

ax AxesSubplot Axes(0.125,0.1;0.775x0.8)

fig function <function figure at 0xa752c6c>

onselect function <function onselect at 0xac0ec34>

toggle_selector function <function toggle_selector at

0xac0ef0c>

x ndarray 100: 100 elems, type float64, 800

bytes y ndarray 100: 100 elems, type

float64, 800 bytes

For the masking, I was planning to use a masking scheme as given below.

Let

say I have an array which “a”

In [14]: a = arange(5)

In [15]: a

Out[15]: array([0, 1, 2, 3, 4])

and my secondary array is “b”

In [16]: b = array([2,3])

What I want to do is to mask a with b values and get an array of:

[array([False, False, True, True, False], dtype=bool)]

That is just an manually created array. I still don’t know how to do

this programmatically in Pythonic fashion.

As I mentioned before I’m not familiar with numpys masked arrays. In this

list

I read several comments on them, but I never used them. But I think they

are

what you are after. Maybe someone else can give you a hint or you try

numpys

online documentation.

All I could provide is again a little manually work using a for-loop. So

something like

mask = zeros(len(a), dtype=bool)

for index in xrange(len(a)): # run through array a

if a[index] in b:

   mask[index] = True

print mask # gives array([False, False, True, True, False],

dtype=bool)

Furthermore I’m not a Python expert and therefore I’m not the guy to ask

for

programing in “Pythonic fashion”. Maybe some else can give a comment?

best regards Matthias

Again thanks for your help.

Gökhan

On Mon, Apr 20, 2009 at 4:09 AM, Matthias Michler > > > > > > > > > > <MatthiasMichler@…361…>wrote:

Hi Gökhan,

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

I use the code from the RectangleSelector class help with your

suggested code. I know that I have to update y-axis accordingly to

x values such

that

their positions and sizes must much so that I can plot them in a

new

plot.

And I know that the answer lies in a mask; I have to create a mask

from

x_new and apply it to y. Do you have any hint on this?

Unfortunately I’m not familiar with numpy masks, but what I would do

is:

xmin = min(eclick.xdata, erelease.xdata)

xmax = max(eclick.xdata, erelease.xdata)

ymin = min(eclick.ydata, erelease.ydata)

ymax = max(eclick.ydata, erelease.ydata)

indices inside x-range

indices = (x>= xmin) & (x <= xmax)

OR: indices for data inside the selected rectangle

#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)

xnew = x[indices]

ynew = y[indices]

Another point is do you have any idea how to save values from

inside onselect action?

What do you mean by saving?

Saving to disk?

for ascii format I use:

from scipy.io import write_array

for numpy arrays you can use

import numpy as np

a = np.arange(10)

a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the

module matplotlib.mlab, which also allows reading different types of

formatted data.

If you think of saving inside the program. You need a global variable

(statement “global x” at the beginning of onselect) otherwise all

variables are deleted at the end of each onselect call.

For some reason my ipython session doesn’t remember values after I

run

the

given script:

see three lines above, please.

best regards Matthias

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

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
x_new = x[(x>= xmin) & (x <= xmax)]
#mask = [x == x_new[i] for i in range(len(x_new))]
#print mask
#print len(x_new)
#print len(y_new)
#fig_new = figure()
#plot(x_new, y_new)
#fig_new.show()

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=‘box’) connect(‘key_press_event’, toggle_selector)

show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > > > > > > > > > > > > > <MatthiasMichler@…361…>wrote:

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.htm

l). 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 ™ 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

Still same with IPython 0.9.1

I will test on Win XP when I get a chance.

Gökhan

···

On Wed, Apr 22, 2009 at 8:54 AM, Gökhan SEVER <gokhansever@…287…> wrote:

Huh,

My definition of kill is just like you said.

Inside Ipython print statements output x_new, and y_new values, but no context saving :frowning:

Worse thing is python rect.py does not nothing, not even with -d switch :frowning: :frowning:

I will try with Ipython 0.9.1.

Gökhan

On Wed, Apr 22, 2009 at 4:40 AM, Matthias Michler <MatthiasMichler@…361…> wrote:

Hi Gökhan,

Hi list,

On Tuesday 21 April 2009 19:44:18 Gökhan SEVER wrote:

Hi Matthias,

Thanks for your reply again. Unfortunately I can’t read x_new or y_new

after I kill the figures (nor when they are active). I don’t know what

exactly wrong in my configuration or IPython. I use IPython 0.10.bzr.r1163

on Fedora 10.

With “kill” you mean just closing the figures with button “X”, isn’t it?

What about adding the line

print x_new, y_new

after the show() in your rect.py-script? Does this give some output in ipython

or if you run the script using “python rect.py” ?

best regards

Matthias

Hopefully, I will solve the masked array riddle by reading more (although

haven’t seen a specific example similar to my question on the numpy

reference pages), if not getting some insight from a numpy expert or like

you said from an expert on masked arrays :slight_smile:

Have a good Tuesday to all.

Gökhan

On Tue, Apr 21, 2009 at 3:21 AM, Matthias Michler > > > > > > > > > > <MatthiasMichler@…361…>wrote:

Hi Gökhan,

Hi list,

Hi experts on masked arrays,

I run the attached script (copied from your last two emails) and I can

use x_new, y_new after closing the figures (where x_new and y_new are the

values

selected in the last selection).

I don’t know, what is going wrong with your script on your system.

my output

In [1]: run rect.py

startposition : (0.276210, 0.592969)

endposition : (0.542339, 0.309375)

used button : 1

startposition : (0.745968, 0.747656)

endposition : (0.745968, 0.747656)

used button : 1

startposition : (0.645161, 0.761719)

endposition : (0.806452, 0.609375)

used button : 3

startposition : (0.808468, 0.607031)

endposition : (0.808468, 0.604688)

used button : 3

startposition : (0.086694, 0.166406)

endposition : (0.137097, 0.070313)

used button : 1

startposition : (0.921371, 0.850781)

endposition : (0.987903, 0.728906)

used button : 1

In [2]: x_new

Out[2]:

array([ 0.92929293, 0.93939394, 0.94949495, 0.95959596, 0.96969697,

   0.97979798])

In [3]: y_new

Out[3]:

array([ 0.80119703, 0.8072005 , 0.81312162, 0.81895978, 0.82471437,

   0.83038482])

In [4]:

#############

Please see my comments below.

On Monday 20 April 2009 23:16:37 Gökhan SEVER wrote:

Thanks for elegant trick Matthias.

I have modified onselect function following your suggestions, and it is

working as I wanted it to be. Select a portion and get a zoomed view in

a new figure.

def onselect(eclick, erelease):

# eclick and erelease are matplotlib events at press and release
global x_new
global y_new
print ' startposition : (%f, %f)' % (eclick.xdata, eclick.ydata)
print ' endposition   : (%f, %f)' % (erelease.xdata,

erelease.ydata) print ’ used button : ', eclick.button

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
indices = (x >= xmin) & (x <= xmax) & (y >= ymin) & (y <= ymax)
x_new = x[indices]
y_new = y[indices]
fig_new = figure()
plot(x_new, y_new)
fig_new.show()

There is still a minute point, that I would like mention again. Even

though

I used global style variables I can’t still see them when I quit the

program.

What I do is run the file within IPython by run command. In my case the

file is ‘rect.py.’ and I do run rect.py. When I quit and do whos

querry,

I

can’t see global x_new nor y_new at the resulting lines:

In [13]: whos

Variable Type Data/Info


RectangleSelector classobj matplotlib.widgets.RectangleSelector

ax AxesSubplot Axes(0.125,0.1;0.775x0.8)

fig function <function figure at 0xa752c6c>

onselect function <function onselect at 0xac0ec34>

toggle_selector function <function toggle_selector at

0xac0ef0c>

x ndarray 100: 100 elems, type float64, 800

bytes y ndarray 100: 100 elems, type

float64, 800 bytes

For the masking, I was planning to use a masking scheme as given below.

Let

say I have an array which “a”

In [14]: a = arange(5)

In [15]: a

Out[15]: array([0, 1, 2, 3, 4])

and my secondary array is “b”

In [16]: b = array([2,3])

What I want to do is to mask a with b values and get an array of:

[array([False, False, True, True, False], dtype=bool)]

That is just an manually created array. I still don’t know how to do

this programmatically in Pythonic fashion.

As I mentioned before I’m not familiar with numpys masked arrays. In this

list

I read several comments on them, but I never used them. But I think they

are

what you are after. Maybe someone else can give you a hint or you try

numpys

online documentation.

All I could provide is again a little manually work using a for-loop. So

something like

mask = zeros(len(a), dtype=bool)

for index in xrange(len(a)): # run through array a

if a[index] in b:

   mask[index] = True

print mask # gives array([False, False, True, True, False],

dtype=bool)

Furthermore I’m not a Python expert and therefore I’m not the guy to ask

for

programing in “Pythonic fashion”. Maybe some else can give a comment?

best regards Matthias

Again thanks for your help.

Gökhan

On Mon, Apr 20, 2009 at 4:09 AM, Matthias Michler > > > > > > > > > > > > > > <MatthiasMichler@…361…>wrote:

Hi Gökhan,

On Friday 17 April 2009 20:21:00 Gökhan SEVER wrote:

Thanks for the pointer Matthias,

That is exactly what I have been looking for.

I use the code from the RectangleSelector class help with your

suggested code. I know that I have to update y-axis accordingly to

x values such

that

their positions and sizes must much so that I can plot them in a

new

plot.

And I know that the answer lies in a mask; I have to create a mask

from

x_new and apply it to y. Do you have any hint on this?

Unfortunately I’m not familiar with numpy masks, but what I would do

is:

xmin = min(eclick.xdata, erelease.xdata)

xmax = max(eclick.xdata, erelease.xdata)

ymin = min(eclick.ydata, erelease.ydata)

ymax = max(eclick.ydata, erelease.ydata)

indices inside x-range

indices = (x>= xmin) & (x <= xmax)

OR: indices for data inside the selected rectangle

#indices = (x>= xmin) & (x <= xmax) & (y>=ymin) & (y<=ymax)

xnew = x[indices]

ynew = y[indices]

Another point is do you have any idea how to save values from

inside onselect action?

What do you mean by saving?

Saving to disk?

for ascii format I use:

from scipy.io import write_array

for numpy arrays you can use

import numpy as np

a = np.arange(10)

a.tofile # Write array to a file as text or binary.

and I think there is also some Matplotlib function for this. In the

module matplotlib.mlab, which also allows reading different types of

formatted data.

If you think of saving inside the program. You need a global variable

(statement “global x” at the beginning of onselect) otherwise all

variables are deleted at the end of each onselect call.

For some reason my ipython session doesn’t remember values after I

run

the

given script:

see three lines above, please.

best regards Matthias

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

xmin = min(eclick.xdata, erelease.xdata)
xmax = max(eclick.xdata, erelease.xdata)
ymin = min(eclick.ydata, erelease.ydata)
ymax = max(eclick.ydata, erelease.ydata)
x_new = x[(x>= xmin) & (x <= xmax)]
#mask = [x == x_new[i] for i in range(len(x_new))]
#print mask
#print len(x_new)
#print len(y_new)
#fig_new = figure()
#plot(x_new, y_new)
#fig_new.show()

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=‘box’) connect(‘key_press_event’, toggle_selector)

show()

Gökhan

On Fri, Apr 17, 2009 at 2:31 AM, Matthias Michler > > > > > > > > > > > > > > > > > > <MatthiasMichler@…361…>wrote:

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.htm

l). 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 ™ 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