waiting on a point

I'm writing a program with a graph. You have to select

    > segments of the graph, which requires 2 points.

    > working with widgets is new to me and im used to working
    > with while loops and what not. I've been just checking to
    > see if i have 0 or 1 points in the on_point wxmpl code, and
    > then if i have 1 and the next point is good opening a
    > dialog to ask and then resetting number of pionts to 0.

    > anyone have any better ideas of how to do this? the amount
    > of "global"/"self.points" variables is driving me nuts

If you want to select a horizontal or vertical region of the graph,
eg, xmin, xmax, the SpanSelector widget is your friend. I believe
recent versions of the wxmpl code worth with mpl events and widgets,
but I haven't tested this.

#!/usr/bin/env python
"""
The SpanSelector is a mouse widget to select a vmin/vmax
range. When you left click drag in the axes, a rectangle shows the
selected region. When you release, the rectangle disappears and a
callback is called with min/max.
"""
import pylab
from matplotlib.widgets import SpanSelector

fig = pylab.figure(figsize=(8,6))
ax = fig.add_subplot(211, axisbg='#FFFFCC')

x,y = 4*(pylab.rand(2,100)-.5)
ax.plot(x,y,'o')
ax.set_xlim(-2,2)
ax.set_ylim(-2,2)
ax.set_title('Press left mouse button and drag to test')

def onselect(vmin, vmax):
    print vmin, vmax

# set useblit True on gtkagg for enhanced performance
span = SpanSelector(ax, onselect, 'horizontal', useblit=False,
                    rectprops=dict(alpha=0.5, facecolor='red') )

ax2 = fig.add_subplot(212)
ax2.plot([1,2,3])

span2 = SpanSelector(ax2, onselect, 'vertical')

pylab.show()

"Kenny" == Kenny Ortmann <yairgo@...1205...> writes:

    > I'm writing a program with a graph. You have to select
    > segments of the graph, which requires 2 points.

    > working with widgets is new to me and im used to working
    > with while loops and what not. I've been just checking to
    > see if i have 0 or 1 points in the on_point wxmpl code, and
    > then if i have 1 and the next point is good opening a
    > dialog to ask and then resetting number of pionts to 0.

    > anyone have any better ideas of how to do this? the amount
    > of "global"/"self.points" variables is driving me nuts

>

If you want to select a horizontal or vertical region of the graph,
eg, xmin, xmax, the SpanSelector widget is your friend.

Although there isn't a wxmpl event for measuring only horizontal or vertical regions, you can use the wxmpl.EVT_SELECTION event to pick a rectangular region. For an example of how that works, you can look at `demos/picking_points.py' in the wxmpl source distribution.

Without knowing more about the application it's hard to recommend what to do to improve things. Perhaps you could add a button to the wxPython application that enables selection, so that the user clicks it and then picks the area of the plot to apply the function to? You could also subclass wxmpl.PlotPanel, add some basic support for the two-point selections, and then reuse that code in your application.

I believe recent versions of the wxmpl code worth with mpl events and
widgets, but I haven't tested this.

Although it is possible to modify `wxmpl.py' to emit mpl events, I'm afraid that wxmpl still doesn't support mpl events or widgets out-of-the-box. There's still too much that can break if the two event-handling systems are incorrectly mixed in an application.

Ken

···

On 09/19/06 15:22, John Hunter wrote: