data plot and interactive change

210 views
Skip to first unread message

zhengqing

unread,
Oct 1, 2012, 7:09:47 PM10/1/12
to wxpytho...@googlegroups.com
Hi,
   I have question and want to see if it can be realized in wxpython.
   I would like to plot data on wxpython, and then use the mouse to select some points which are plotted, and then move the mouse to manipulate those selected points, Then program use certain curve fitting to get a new modified curve.
   Please let me know if there is any examples or suggestions can give the similar function in wxpython.
 
 
Regards!
 
zhengqing(Forrest)

Chris Barker

unread,
Oct 2, 2012, 12:42:56 PM10/2/12
to wxpytho...@googlegroups.com
On Mon, Oct 1, 2012 at 4:09 PM, zhengqing <zhengq...@gmail.com> wrote:
> Hi,
> I have question and want to see if it can be realized in wxpython.
> I would like to plot data on wxpython, and then use the mouse to select
> some points which are plotted, and then move the mouse to manipulate those
> selected points, Then program use certain curve fitting to get a new
> modified curve.

of course it can be done with wxPython, but I supopse yopu'd rather
not write ALL teh code yourself.


> Please let me know if there is any examples or suggestions can give the
> similar function in wxpython.

wx.lib.floatcanvas could help here.

There are a number of examples in SVN that aren't with teh demo. IN
particular, the "PolyEditor" demo should be helpful:


http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/PolyEditor.py?revision=51716&view=markup

I"d suggest:

* Create a new DrawObject for you fitted line, based on the Line
and/or Spline DrawObjects.

* Create a different drawobject for the "control points" of your line
-- based on the PointSet object.

* you should be able to link those tow together, so that your fitten
line uses the PointSet points (see the ConnectorLine Object in the
ProcessDiagram demo for an exampel of this)

* model your editing code off of the PolyEditor demo.

Post further questions to teh floatcanvas mailing list:

http://mail.paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

-Chris


-


Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

Benjamin Jessup

unread,
Oct 3, 2012, 8:36:18 AM10/3/12
to wxpytho...@googlegroups.com
If are not attached to the idea of 'interactive points', you could use
matplotlib for the plotting, and then use other widgets to edit the data
(maybe a wx.Grid?). After each edit, you would pass the data to the
curve fit routine, and have the curve fit routine spit out the plot points.

Gadget/Steve

unread,
Oct 3, 2012, 10:36:20 AM10/3/12
to wxpytho...@googlegroups.com
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en
Take a look at the PyPlot sample - a lot of what you are asking for is
already in there - draw plots, select points, etc., and it could
probably provide inspiration for how to do what you would like to do.

Gadget/Steve

Chris Barker

unread,
Oct 3, 2012, 12:25:41 PM10/3/12
to wxpytho...@googlegroups.com
On Wed, Oct 3, 2012 at 5:36 AM, Benjamin Jessup <b...@abzinc.com> wrote:
> If are not attached to the idea of 'interactive points', you could use
> matplotlib for the plotting, and then use other widgets to edit the data
> (maybe a wx.Grid?). After each edit, you would pass the data to the curve
> fit routine, and have the curve fit routine spit out the plot points.

Actually, MPL does support event handling and picking, so you could do
the interactive points with that as well. If you want your plots
pretty and they are standard axes, etc, (i.e want other things MPL
give you) that's probably a good way to go.

Check out:

http://www.youtube.com/watch?v=nCv_MhaeFo8

for a really cool example. (and you can learn a bit about basic
statistics as well)

-Chris


--

zhengqing

unread,
Oct 3, 2012, 8:27:15 PM10/3/12
to wxpytho...@googlegroups.com
Thank you very much for all your help.
just creat a demo using wx.lib.plot.
 
It works, and need to add a spline fitting function next.
 
I am not sure if this is a good way to write classes. Please let me know if there is any suggestion that can make the code clean and easy to read and follow.
 
Any book about good style of programming?
 
Regards!
 
zhengqing(Forrest)
wxPlotEditor.py

Chris Barker

unread,
Oct 4, 2012, 12:15:44 PM10/4/12
to wxpytho...@googlegroups.com
On Wed, Oct 3, 2012 at 5:27 PM, zhengqing <zhengq...@gmail.com> wrote:
> It works, and need to add a spline fitting function next.

wx.DC has a nifty spline drawing function, though you may want
something specific. I"d expect there is some coce out there for bezier
splines in numpy.python, though I haven't seen it.

> I am not sure if this is a good way to write classes. Please let me know if
> there is any suggestion that can make the code clean and easy to read and
> follow.

some comments:

* don't use numpy.oldnumeric if you can help it (and you probably
can). And the standard way to import numpy these days is:

import numpy as np

"""data1 = 2.*_Numeric.pi*_Numeric.arange(200)/200.
data1.shape = (100, 2)
data1[:,1] = _Numeric.sin(data1[:,0])
"""

can (and probably should) be written something like:

t = np.linspace(0, np.pi, 100)
data1 = np.column_stack( (t, np.sin(t)) )

* I think I'd keep a PlotGraphics object around in your DrawData
class, and have the various methods modify it, rather than make a new
one each time. That way you can split out axis labeling, etc.

but it generally looks pretty good.

-Chris

nepix32

unread,
Oct 5, 2012, 6:37:22 AM10/5/12
to wxPython-users
On Oct 4, 2:27 am, zhengqing <zhengqing...@gmail.com> wrote:
> Thank you very much for all your help.
> just creat a demo using wx.lib.plot.

> It works, and need to add a spline fitting function next.
I used interpolate.UnivariateSpline from scipy

The smoothing looks better (is better controllable) than the built-in
PolySpline from wx.lib.plot
Reply all
Reply to author
Forward
0 new messages