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

Reply via email to