Hi All:

Thanks to Michael & Ryan, I got my imshow call displaying the correct
data range on the x axis!  

However, when I now use a toolbar to zoom the image, I'm getting a
divide by zero error (see traceback below)

I'm using Python 2.5.2, wx 2.8.7.1, and Matplotlib 0.98.5.2 on win32.

Thanks for your (hopefully) continued patience with these newbie
questions!

amb

 

Here is the call to imshow that I modified:

self.myImage =
self.axes.imshow(self.image_data,aspect='auto',extent=[self.pageOffset,s
elf.pageOffset+self.pageSizeSamps,self.numChans,1])

from:

self.myImage = self.axes.imshow(self.image_data,aspect='auto')

The old version zooms just fine with no error.  This code is called in a
menu event handler

 

Here is how I created the figure & toolbar:

 
########################################################################
#########################

    def SetupPlot(self):

        self.figure = Figure()

        self.axes = self.figure.add_subplot(111)

        self.canvas = FigureCanvas(self, -1, self.figure)

        self.data = np.zeros((self.numChans,self.pageSizeSamps))

        self.myImage = self.axes.imshow(self.data,aspect='auto')

        self.sizer.Add(self.canvas,pos=(1,1))

        self.add_toolbar()  

 

 
########################################################################
#########################

    def add_toolbar(self):

        self.toolbar = NavigationToolbar2Wx(self.canvas)

        self.toolbar.Realize()

        # On Windows platform, default window size is incorrect, so set

        # toolbar width to figure width.

        tw, th = self.toolbar.GetSizeTuple()

        fw, fh = self.canvas.GetSizeTuple()

        # By adding toolbar in sizer, we are able to put it at the
bottom

        # of the frame - so appearance is closer to GTK version.

        # As noted above, doesn't work for Mac.

        self.toolbar.SetSize((fw, th))

        self.sizer.Add(self.toolbar,pos=(2,1))

        # update the axes menu on the toolbar

        self.toolbar.update()

 

Here is the error Traceback:

Traceback (most recent call last):

  File
"C:\Python25\Lib\site-packages\matplotlib\backends\backend_wx.py", line
1

225, in _onLeftButtonUp

    FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt)

  File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line
1198, i

n button_release_event

    self.callbacks.process(s, event)

  File "C:\Python25\Lib\site-packages\matplotlib\cbook.py", line 155, in
process

 

    func(*args, **kwargs)

  File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line
2048, i

n release_zoom

    self.draw()

  File "C:\Python25\Lib\site-packages\matplotlib\backend_bases.py", line
2070, i

n draw

    self.canvas.draw()

  File
"C:\Python25\Lib\site-packages\matplotlib\backends\backend_wxagg.py",
lin

e 60, in draw

    FigureCanvasAgg.draw(self)

  File
"C:\Python25\Lib\site-packages\matplotlib\backends\backend_agg.py", line

279, in draw

    self.figure.draw(self.renderer)

  File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 772,
in draw

    for a in self.axes: a.draw(renderer)

  File "C:\Python25\Lib\site-packages\matplotlib\axes.py", line 1545, in
draw

    im.draw(renderer)

  File "C:\Python25\Lib\site-packages\matplotlib\image.py", line 233, in
draw

    im = self.make_image(renderer.get_image_magnification())

  File "C:\Python25\Lib\site-packages\matplotlib\image.py", line 220, in
make_im

age

    rx = widthDisplay / numcols

ZeroDivisionError: float division

________________________________

From: matplotlib-users-boun...@lists.sourceforge.net
[mailto:matplotlib-users-boun...@lists.sourceforge.net] On Behalf Of
Lewis, Ambrose J.
Sent: Saturday, February 14, 2009 7:07 AM
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] x axis & imshow...

 

Thanks Michael & Ryan!
Worked great!
amb


-----Original Message-----
From: Michael Droettboom [mailto:md...@stsci.edu]
Sent: Fri 2/13/2009 1:14 PM
To: Lewis, Ambrose J.
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] x axis & imshow...

You can pass "extent=(left, right, bottom, top)" to imshow to specify
what the pixels in the array correspond to in data space.

Mike

Lewis, Ambrose J. wrote:
>
> Hi All:
>
> I'm working on a wxPython GUI that uses matplotlib.
>
> This program reads "chunks" of a data file into a numpy array and than
> plots it using imshow.
>
> The first chunk works great. But, when I load chunks 2 to N, how can I
> specify the different values for the labels on the x axis?
>
> I tried using "axes.set_xlim". This did reposition the x axis as
> hoped, but the data is always being drawn back at the "zero" offset.
>
> Is there a way to tell the axis to map the array to a different x
range?
>
> I can't read the whole file at once, it's just too big
>
> THANXS
>
> amb
>
>
------------------------------------------------------------------------
>
>
------------------------------------------------------------------------
------
> Open Source Business Conference (OSBC), March 24-25, 2009, San
Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the
Enterprise
> -Strategies to boost innovation and cut costs with open source
participation
> -Receive a $600 discount off the registration fee with the source
code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
>
------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>  

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA



------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to