imshow update norm make my app crash.

Hi guys, continuing exploring matplotlib
capabilities J

I’ve applied the idea you’ve
said later about colormap.

Now I would like on an event to refresh my
view so I’ve written this code:

def InitCode(self):

self.norm
= plt.Normalize(vmin=0, vmax=255)

self.cmap = cm.jet

im_full = full_sonar.imshow( z, aspect= ‘auto’, cmap=self.cmap, norm=self.norm,
interpolation=‘quadric’)

im_zoom = zoomed_sonar.imshow( z, aspect= ‘auto’,cmap=self.cmap,
norm=self.norm, interpolation=‘quadric’)

self.fig.colorbar(im_full,cax=cax,orientation=‘vertical’,extend=‘both’)

self.im_full = im_full

self.im_zoom = im_zoom

def
updateSonarView(self):

self.im_full.set_cmap(self.cmap)

self.im_zoom.set_cmap(self.cmap)

self.im_full.set_norm(self.norm)

self.im_zoom.set_norm(self.norm)

self.fig.canvas.draw()

def OnUpdateButton(self,
event):

self.low_clutter_val = self.clutter_low.GetPosition()

self.high_clutter_val = self.clutter_high.GetPosition()

self.norm = plt.Normalize(vmin=self.low_clutter_val,
vmax=self.high_clutter_val)

self.updateSonarView()

But I get this error from the lib :

Traceback (most recent call last):

File
“./Filters\A1Filter.py”, line 183, in OnUpdateButton

self.updateSonarView()

File “./Filters\A1Filter.py”,
line 157, in updateSonarView

self.im_full.set_norm(self.norm)

File
“C:\Python25\Lib\site-packages\matplotlib\cm.py”, line 129, in
set_norm

self.changed()

File
“C:\Python25\Lib\site-packages\matplotlib\image.py”, line 123, in changed

cm.ScalarMappable.changed(self)

File
“C:\Python25\Lib\site-packages\matplotlib\cm.py”, line 174, in
changed

self.callbacksSM.process(‘changed’, self)

File
“C:\Python25\Lib\site-packages\matplotlib\cbook.py”, line 152, in
process

func(*args, **kwargs)

File
“C:\Python25\Lib\site-packages\matplotlib\figure.py”, line 1028, in
on_changed

cb.update_bruteforce(m)

File
“C:\Python25\Lib\site-packages\matplotlib\colorbar.py”, line 649, in
update_bruteforce

self.draw_all()

File “C:\Python25\Lib\site-packages\matplotlib\colorbar.py”,
line 221, in draw_all

self._process_values()

File
“C:\Python25\Lib\site-packages\matplotlib\colorbar.py”, line 458, in
_process_values

b =
self.norm.inverse(self._uniform_y(self.cmap.N+1))

File
“C:\Python25\Lib\site-packages\matplotlib\colors.py”, line 652, in
inverse

return vmin + val *
(vmax - vmin)

File
“C:\Python25\Lib\site-packages\numpy\ma\core.py”, line 1686, in
mul

return multiply(self,
other)

File “C:\Python25\Lib\site-packages\numpy\ma\core.py”,
line 503, in call

result = self.f(d1, d2,
*args, **kwargs).view(get_masked_subclass(a,b))

ValueError: shape mismatch: objects cannot
be broadcast to a single shape

UpdateSonarview works flawlessly if I
modify the colormap (self.cmap) and call it then.

If I modify self.norm and call
UpdateSonarView I get this crash.

Is it a bug from my bad usage of the lib?
If not, I can perhaps send you a stripped down file showing the problem?

Using matplotlib 0.98.1 under windows.

Laurent

I would like to see what

        self.low_clutter_val = self.clutter_low.GetPosition()

        self.high_clutter_val = self.clutter_high.GetPosition()

low and high clutter val are (can you print them, as well as their type, eg

  print low', type(self.low_clutter_val), self.low_clutter_val

and likewise for the high val. From the error, it looks lik they are
not scalars.

JDH

···

On Tue, Jul 29, 2008 at 6:52 PM, Laurent Dufrechou <laurent.dufrechou@...287...> wrote:

I've applied the idea you've said later about colormap.

Now I would like on an event to refresh my view so I've written this code:

Ho you got the point...
self.clutter_low.GetPosition() didn't returned an int...
self.clutter_low.GetValue return an int an it works now.
I missed this because I thought that
self.norm = plt.Normalize(vmin=self.low_clutter_val,
vmax=self.high_clutter_val)
would have crashed before in this case, but seems it does not do any
computation on Normalize call.

Anyhow, thank you a lot, sorry to have send this error, I could have read my
code deeper first.

Regards,
Lauent

···

-----Message d'origine-----
De : John Hunter [mailto:jdh2358@…287…]
Envoyé : mercredi 30 juillet 2008 02:04
À : Laurent Dufrechou
Cc : matplotlib-users@lists.sourceforge.net
Objet : Re: [Matplotlib-users] imshow update norm make my app crash.

On Tue, Jul 29, 2008 at 6:52 PM, Laurent Dufrechou > <laurent.dufrechou@...287...> wrote:

> I've applied the idea you've said later about colormap.
>
> Now I would like on an event to refresh my view so I've written this
code:

I would like to see what

        self.low_clutter_val = self.clutter_low.GetPosition()

        self.high_clutter_val = self.clutter_high.GetPosition()

low and high clutter val are (can you print them, as well as their
type, eg

  print low', type(self.low_clutter_val), self.low_clutter_val

and likewise for the high val. From the error, it looks lik they are
not scalars.

JDH