plot change position in wxpython when redraw

Dear list fellows,

I am writing an app focused in structural geology, using wxpython and
matplotlib. To be quite honest, I'm not sure if this question should
go here or in the wxpython list (so to avoid cross-posting, I'll try
here first).

The app uses matplotlib to plot data from orientation data as points
or lines (circles) in a stereonet (a circular plot using Lambert's
equal-area projection). So far, it is in it very early stages, I have
two panels (one for data display and the other for the plot itself), I
can open CSV files and I can even plot them! I must say I am surprised
to have achieved all this in about two week of work, with nearly no
experience in python (just some small scripts), and no experience at
all with wxpython/matplotilib.

My problem now is that I can plot the data in three different ways,
and the plots are overlaid on to the last one (I still don't know if
this kind of behaviour should be removed or not), but the thing is,
that depending on the order in which I plot the data, the graphic
changes its position in the window!

Just a brief explanation of the interface first: The option are in the
toolbar, the first button opens a data file, the second one creates
the stereonet, the third and fourfh plot data as points and the fifth
plot as lines.

Try this with the attached code: open the data (1st btn), create the
plot (2nd btn), then plot the data as points (3rd and 4th btns) and
then as lines (5th btn). OK, now clean the plot (2nd btn) and plot
first as lines (5th btn) and then as points (3rd or 4th btns), and you
will see that the plot moves to the left! At least for me (Ubuntu
Linux).

If you could give me any advice on why this is happening (and how to
prevent it), I will be very thankful.

PS. I know my code is not as good as it could. I'm new to
OO-programing, so I still need to understand properly how to work with
classes, etc, and I promisse I will improve the code in the near
future! (any advices here are also welcome!)

Many thanks for your help

Carlos

data.txt (255 Bytes)

pystereo16.py (8.78 KB)

application.png

chart_line.png

···

--
Carlos Henrique Grohmann - Geologist D.Sc.
a.k.a. Guano - Linux User #89721
ResearcherID: A-9030-2008
carlos dot grohmann at gmail dot com
http://www.igc.usp.br/pessoais/guano/
_________________
"Good morning, doctors. I have taken the liberty of removing Windows
95 from my hard drive."
--The winning entry in a "What were HAL's first words" contest judged
by 2001: A SPACE ODYSSEY creator Arthur C. Clarke

Can’t stop the signal.

Carlos Guâno Grohmann wrote:

I am writing an app focused in structural geology, using wxpython and
matplotlib. To be quite honest, I'm not sure if this question should
go here or in the wxpython list

Well, that depends on whether the shift is a shift of the wxWindow, or if MPL is somehow putting your plot in a different place in the Figure. I do see the circle get smaller sometimes, though it doesn't shift for me -- I think it's an MPL issue:

OS-X 10.4 PPC, Python2.5.4, wxPython2.8.9.1, MPL 0.98.5.2

The issue may be that you are creating anew axis in each call, but I think what you want is to be using the same axis each time.

Try this with the attached code:

Your code doesn't run as-is -- the images are expected to be in a particular directory. -- you really need to make it as easy as possible for folks to test your code:

http://wiki.wxpython.org/MakingSampleApps

A few other comments from a quick look.

  - You're using tabs to indent. Like it or not, 4 spaces is the python standard now.

  - hard coded IDs are a pretty old style:
     http://wiki.wxpython.org/wxPython%20Style%20Guide

  - you might want to look into wxPython's "img2py" scripts, for embedding small icons in Python code.

  - I think Your PlotPanel has one more sizer that required -- something like this should work:

      box1 = wx.BoxSizer(wx.VERTICAL)
    st1 = wx.StaticText(self, -1, 'Plot')
    box1.Add(st1, 0, wx.RIGHT)

    self.figure = Figure(figsize=(6,6))#
    self.canvas = FigureCanvas(self, -1, self.figure)

    box1.Add(self.canvas, 1, wx.EXPAND|wx.ALL, 4)
    self.SetSizer(box1)

  open the data (1st btn), create the

···

plot (2nd btn), then plot the data as points (3rd and 4th btns) and
then as lines (5th btn). OK, now clean the plot (2nd btn) and plot
first as lines (5th btn) and then as points (3rd or 4th btns), and you
will see that the plot moves to the left! At least for me (Ubuntu
Linux).

If you could give me any advice on why this is happening (and how to
prevent it), I will be very thankful.

PS. I know my code is not as good as it could. I'm new to
OO-programing, so I still need to understand properly how to work with
classes, etc, and I promisse I will improve the code in the near
future! (any advices here are also welcome!)

Many thanks for your help

Carlos

------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------

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

--
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@...259...