Question about plot graph in wxpython

Hi All,

I have uploaded the code.

The code is for ploting the CIE diagram on the backgroud.of the frame.

The question here is that why the plot speed is that slow. is that a way to make it faster beside using a better computer? :slight_smile:

And for the shaped frame, how to add a panel in it? please share a sample code with me.

If I would like to plot the CIE diagram using the wx.lib.plot, is there a good way to do that?

Thank you very much!

CIE_1931_color_space.py (10.7 KB)

CIE_1931_Standard_Colorimetric_Observer_data.py (40.6 KB)

Hi All,
     I have uploaded the code.
     The code is for ploting the CIE diagram on the backgroud.of the frame.
     The question here is that why the plot speed is that slow. is that
a way to make it faster beside using a better computer? :slight_smile:

Any time you are drawing a single pixel at a time to the screen it will be slow. Drawing to a bitmap via a wx.MemoryDC will be faster, and then you can just draw the bitmap to the screen in one operation.

     And for the shaped frame, how to add a panel in it? please share a
sample code with me.

Just make the panel be a child of the frame like usual. The frame's shape should clip the panel as expected.

     If I would like to plot the CIE diagram using the wx.lib.plot, is
there a good way to do that?

No but it is probably easy in matplotlib.

···

On 7/10/12 5:09 PM, zhengqing wrote:

--
Robin Dunn
Software Craftsman

Hi Robin,

I want to modify the wx.lib.plot.PolyLine.

Because this function only can draw a line with a same color, if we want to draw lines with different color, we need to create more Polyline.

Please take a look at the attached file.

I try to modify the draw function, which can take a coordinates list, and a color list, then draw the line with different color one time.

But at this moment, it doesn’t work, I am not sure why.

Thank you very much, I really appreciate if you can help.

Regards!

zhengqing(Forrest)

New Text Document (2).txt (825 Bytes)

···

On Tuesday, July 10, 2012 6:34:49 PM UTC-7, Robin Dunn wrote:

On 7/10/12 5:09 PM, zhengqing wrote:

Hi All,
I have uploaded the code.
The code is for ploting the CIE diagram on the backgroud.of the frame.
The question here is that why the plot speed is that slow. is that
a way to make it faster beside using a better computer? :slight_smile:

Any time you are drawing a single pixel at a time to the screen it will
be slow. Drawing to a bitmap via a wx.MemoryDC will be faster, and then
you can just draw the bitmap to the screen in one operation.

 And for the shaped frame, how to add a panel in it? please share a

sample code with me.

Just make the panel be a child of the frame like usual. The frame’s
shape should clip the panel as expected.

 If I would like to plot the CIE diagram using the wx.lib.plot, is

there a good way to do that?

No but it is probably easy in matplotlib.

–
Robin Dunn
Software Craftsman
http://wxPython.org

Are you getting any exceptions? Are you sure that coord is not None? What are width and style?

The line creating the pen looks a little suspicious. Try this instead:

     pen = wx.Pen(wx.Colour(*colour[i]), width, style)

If this doesn't help then please make a runnable sample that people can try for themselves to see what is going wrong. MakingSampleApps - wxPyWiki

···

On 8/22/12 3:30 PM, zhengqing wrote:

Hi Robin,
     I want to modify the wx.lib.plot.PolyLine.
     Because this function only can draw a line with a same color, if we
want to draw lines with different color, we need to create more Polyline.
     Please take a look at the attached file.
     I try to modify the draw function, which can take a coordinates
list, and a color list, then draw the line with different color one time.
     But at this moment, it doesn't work, I am not sure why.

--
Robin Dunn
Software Craftsman

Hi Robin,

Here is the code.

But it is really slow. it takes long time to zoom in and zoom out.

I tried to modify the PolyLine class to draw it, and it looks like the speed doesn’t improve.

Is there any way to make it smooth in redrawing, resizing and zooming?

Really appreciate if you can help.

Regards!

zhengqing(Forrest)

CIEcolorDiagramTest.py (6.21 KB)

CIE_1931_Standard_Colorimetric_Observer_data.pyc (63.3 KB)

···

On Wednesday, August 22, 2012 7:35:48 PM UTC-7, Robin Dunn wrote:

On 8/22/12 3:30 PM, zhengqing wrote:

Hi Robin,
I want to modify the wx.lib.plot.PolyLine.
Because this function only can draw a line with a same color, if we
want to draw lines with different color, we need to create more Polyline.
Please take a look at the attached file.
I try to modify the draw function, which can take a coordinates
list, and a color list, then draw the line with different color one time.
But at this moment, it doesn’t work, I am not sure why.

Are you getting any exceptions? Are you sure that coord is not None?
What are width and style?

The line creating the pen looks a little suspicious. Try this instead:

 pen = wx.Pen(wx.Colour(*colour[i]), width, style)

If this doesn’t help then please make a runnable sample that people can
try for themselves to see what is going wrong.
http://wiki.wxpython.org/MakingSampleApps

–
Robin Dunn
Software Craftsman
http://wxPython.org

The wx.lib.plot module is not designed to be able to handle plots with tens of thousands of line segments (plot objects) on it. You should really look at using matplotlib or Chaco instead, and also using numpy for building and manipulating your data set instead of Python lists. A large portion of the startup time of your sample was spent in creating the lists of lists of lists for your data set, and then making 37000 PolyLines each with a numpy array representing 1 tiny line segment.

Using one of the more advanced plotting libs will enable you to build and keep your data in a numpy array from start to finish and will also be much more efficient about drawing the plot. The wx.lib.plot module is intended to be used for simple things, with up to medium-small data sets, and be simple enough for the average programmer to understand and use and customize. Matplotlib and Chaco are much more complex, but are also lots better at doing much more complex things, and are better able to handle larger sets of data.

···

On 8/22/12 9:30 PM, zhengqing wrote:

Hi Robin,
     Here is the code.
     But it is really slow. it takes long time to zoom in and zoom out.
     I tried to modify the PolyLine class to draw it, and it looks like
the speed doesn't improve.
     Is there any way to make it smooth in redrawing, resizing and zooming?
     Really appreciate if you can help.

--
Robin Dunn
Software Craftsman

Another option would be wx.lib.floatcanvas -- all numpy, and pretty
easy to buid a custom drawobject, like what I think you want with
polylines changing color as you go.

What you dont get is nice auto-sizing of axis, etc, but it's not hard
to do if you only want one plot per frame.

See the demo in the main wxPython demo, and also there is some info an
examples in the TRAC page:

http://trac.paulmcnett.com/floatcanvas

and there are a bunch of simple demos in the source:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/

-Chris

···

On Thu, Aug 23, 2012 at 11:17 AM, Robin Dunn <robin@alldunn.com> wrote:

Using one of the more advanced plotting libs will enable you to build and
keep your data in a numpy array from start to finish and will also be much
more efficient about drawing the plot.

--

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.Barker@noaa.gov

Hi Robin,

Thanks.

I will try those packages you suggested. The reason I would like to use the wx.lib.plot is to keep the program simple which makes me know what it is doing. I am afraid that if I use matlibplot package, it will make this app large after compiling into a exe file and I am also not sure how to compile to exe with the matlibplot package.

I am also curious how matlibplot deal with large data sets, is there any way I can learn how it works?

Regards!

zhengqing(Forrest)

···

On Thursday, August 23, 2012 11:17:13 AM UTC-7, Robin Dunn wrote:

On 8/22/12 9:30 PM, zhengqing wrote:

Hi Robin,
Here is the code.
But it is really slow. it takes long time to zoom in and zoom out.
I tried to modify the PolyLine class to draw it, and it looks like
the speed doesn’t improve.
Is there any way to make it smooth in redrawing, resizing and zooming?
Really appreciate if you can help.

The wx.lib.plot module is not designed to be able to handle plots with
tens of thousands of line segments (plot objects) on it. You should
really look at using matplotlib or Chaco instead, and also using numpy
for building and manipulating your data set instead of Python lists. A
large portion of the startup time of your sample was spent in creating
the lists of lists of lists for your data set, and then making 37000
PolyLines each with a numpy array representing 1 tiny line segment.

Using one of the more advanced plotting libs will enable you to build
and keep your data in a numpy array from start to finish and will also
be much more efficient about drawing the plot. The wx.lib.plot module
is intended to be used for simple things, with up to medium-small data
sets, and be simple enough for the average programmer to understand and
use and customize. Matplotlib and Chaco are much more complex, but are
also lots better at doing much more complex things, and are better able
to handle larger sets of data.

–
Robin Dunn
Software Craftsman
http://wxPython.org

Hi Chris,

Thank you for you help.

And in the code, I use the PolyLine to get this color diagram. But the ultimate goal is to plot this color diagram with plotpoints, which means draw each pixcel with the correct color. I am not sure how to do it now, I tryied as I posted the first time, but it is slow.

I will try floatcanvas, but do you konw if it has better drawing speed?

Regards!

zhengqing(Forrest)

···

On Thursday, August 23, 2012 12:25:12 PM UTC-7, Chris Barker wrote:

On Thu, Aug 23, 2012 at 11:17 AM, Robin Dunn ro...@alldunn.com wrote:

Using one of the more advanced plotting libs will enable you to build and
keep your data in a numpy array from start to finish and will also be much
more efficient about drawing the plot.

Another option would be wx.lib.floatcanvas – all numpy, and pretty
easy to buid a custom drawobject, like what I think you want with
polylines changing color as you go.

What you dont get is nice auto-sizing of axis, etc, but it’s not hard
to do if you only want one plot per frame.

See the demo in the main wxPython demo, and also there is some info an
examples in the TRAC page:

http://trac.paulmcnett.com/floatcanvas

and there are a bunch of simple demos in the source:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/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

Hi zhengqing,

Hi Robin,
    Thanks.
    I will try those packages you suggested. The reason I would like to use
the wx.lib.plot is to keep the program simple which makes me know what it is
doing. I am afraid that if I use matlibplot package, it will make this app
large after compiling into a exe file and I am also not sure how to compile
to exe with the matlibplot package.

As a wise person recently told me, memory and disk space are quite
cheap these days! To create an exe file, which suggests you are using
Windows, you can try to use py2exe which will enable you to bundle
your python program with matplotlib, wx, and many other popular
programs. See http://www.py2exe.org

    I am also curious how matlibplot deal with large data sets, is there any
way I can learn how it works?

It is open source so you can find out exactly how it works if you want
to! http://matplotlib.sourceforge.net

Cheers,

MarkL

···

On 24 August 2012 10:00, zhengqing <zhengqinggan@gmail.com> wrote:

On Fri, Aug 24, 2012 at 4:43 AM, Mark Livingstone > As a wise person
recently told me, memory and disk space are quite

cheap these days!

absolutely, -- but bandwidth not so much, at least nto for everyone.

That being said, I use Matplotlib when I've got real plotting to do.
The trick with using it with py2exe is getting all the data files it
needs in the right place, but there is a little function provided by
MPL that helps that -- if you google pyexe and matplotlib, you shoudl
be abel to find help.

And if you wan to use pyInstaller or ??? the same tricks will probably help.

    I am also curious how matlibplot deal with large data sets, is there any
way I can learn how it works?

It is entirely based on numpy, which will help with the parse data
sets -- I think it also has some data thinning algorithms (i.e. when
zoomed out, a number of data points may be at the same pixel location,
so why plot them all?

That being said, it's got some nifty transform magic and all that
slows things down a bit.

Check the Matplotlib lists and source for more info -- or just give it
a try with your data.

-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.Barker@noaa.gov

I suspect ANY code that tried to plot each pixel with a python
function call is going to be slow.

wx.DC has a DrawPointList(), which could be a great deal faster:

Draw a list of points as quickly as possible.

    :param points: A sequence of 2-element sequences representing
                    each point to draw, (x,y).
    :param pens: If None, then the current pen is used. If a
                    single pen then it will be used for all points. If
                    a list of pens then there should be one for each point
                    in points.

though if you have thousands, that means you'll need thousands of
wx.Pens -- not sure if that will be an issue.

FloatCanvas uses DrawPointList for the FC.PointSet DrawObject, so it's
about as fast as it could be. But it only supports every piunt being
the same color. however, it wouldn't be too hard to create a new
version that gives a separate color per point.

There is also this:
http://trac.paulmcnett.com/floatcanvas/wiki/SmoothLines

Which shows you how to use wx.GraphicsContext with floatCanvas to draw
lines with gradient colors -- unfortunately, GraphicsContext doesn't
directly support that, so it's kludged with a narrow polygon.

If you really need top performance, PyOpenGL will do it -- but with a
lot more complex code to write...

-Chris

···

On Thu, Aug 23, 2012 at 5:06 PM, zhengqing <zhengqinggan@gmail.com> wrote:

Hi Chris,
    Thank you for you help.
    And in the code, I use the PolyLine to get this color diagram. But the
ultimate goal is to plot this color diagram with plotpoints, which means
draw each pixcel with the correct color. I am not sure how to do it now, I
tryied as I posted the first time, but it is slow.

--

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.Barker@noaa.gov