0

I am having an issue with plotting in the ipython notebook. Basically, the same code generates the plots I desire when I execute it in the Canopy editor command window, but balks in the notebook with just

KeyError:matplotlib.axes.AxesSubplot object at 0x53e2f310

I was unable to make sense out of this discrepancy between the environments. Until I ran the print(IPython.sys_info()) command in the two environments.

In Canopy IPython.sys_info() returns:

{'commit_hash': 'c433019', 'commit_source': 'installation', 'default_encoding': 'UTF-8', 'ipython_path': '/usr/local/Canopy/appdata/canopy-1.0.3.1262.rh5-x86_64/lib/python2.7/site-packages/IPython', 'ipython_version': '1.0.dev', 'os_name': 'posix', 'platform': 'Linux-3.8.0-26-generic-x86_64-with-debian-wheezy-sid', 'sys_executable': '/home/kambiz/Enthought/Canopy_64bit/User/bin/python', 'sys_platform': 'linux2', 'sys_version': '2.7.3 | 64-bit | (default, Jun 14 2013, 18:32:48) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]'}

In Notebook IPython.sys_info() returns:

{'commit_hash': '177894e', 'commit_source': 'installation', 'default_encoding': 'UTF-8', 'ipython_path': '/home/kambiz/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython', 'ipython_version': '0.13.1', 'os_name': 'posix', 'platform': 'Linux-3.8.0-26-generic-x86_64-with-debian-wheezy-sid', 'sys_executable': '/home/kambiz/Enthought/Canopy_64bit/User/bin/python', 'sys_platform': 'linux2', 'sys_version': '2.7.3 | 64-bit | (default, Jun 14 2013, 18:32:48) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]'}

I noticed that the Ipython_path point to different paths where the EPD files reside, which in turn point to different versions of ipython!!! I am not sure how this happened, nor exactly how to fix it. Such that both environments run the same version, which executes code the same way.

The snippet of code that causes a matplotlib failure with IPython version 0.13.1 is:

import pylab as pl
...
fig, axes = pl.subplots(len(evokeds), sharex=True, sharey=True, tight_layout=True,                     figsize=(8, 11), dpi=100)
figname = (data_path + subj_queue[r] + '/' + subj_queue[r] + '_evokeds.pdf')
for evoked, ax, cond in zip(evokeds, axes.flatten(), ['Known', 'Known-ctrl', 'Unknown', 'Unkown-ctrl']):
    evoked.plot(picks=mag_picks, axes=ax)
    ax.set_title('%s' % cond)
fig.savefig(figname, format='pdf')

Where evokeds is of class list of Evoked objects generated by the third-party class function mne.Epochs.average(). The plotting command that crashes matplotlib in IPython 0.13.1 is also a class function mne.fiff.evoked.plot() from the mne module. A publicly available example that will also generate the same plotting issue in an external Notebook with Ipython 0.13.1 is available here. The error evoked.plot(picks=mag_picks, axes=ax) generates is a KeyError:. Here is a screen shot of the subplots:

enter image description here

This is the complete Traceback:

KeyError Traceback (most recent call last) in () 25 figname = (data_path + subj_queue[r] + '/' + subj_queue[r] + '_evokeds.pdf') 26 for evoked, ax in zip(evokeds, axes.flatten()): ---> 27 evoked.plot(picks=mag_picks, axes=ax) 28 ax.set_title('%s' % cond) 29 fig.savefig(figname, format='pdf')

/usr/local/mne-python/mne/fiff/evoked.pyc in plot(self, picks, exclude, unit, show, ylim, proj, xlim, hline, units, scalings, titles, axes) 396 plot_evoked(self, picks=picks, exclude=exclude, unit=unit, show=show, 397 ylim=ylim, proj=proj, xlim=xlim, hline=hline, units=units, --> 398 scalings=scalings, titles=titles, axes=axes) 399 400 def plot_topomap(self, times=None, ch_type='mag', layout=None, vmax=None,

/usr/local/mne-python/mne/viz.pyc in plot_evoked(evoked, picks, exclude, unit, show, ylim, proj, xlim, hline, units, scalings, titles, axes) 1213 1214 D = this_scaling * evoked.data[idx, :] -> 1215 pl.axes(ax) 1216 ax.plot(times, D.T) 1217 if xlim is not None:

/home/kambiz/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/pyplot.pyc in axes(*args, **kwargs) 650 651 if isinstance(arg, Axes): --> 652 a = gcf().sca(arg) 653 else: 654 rect = arg

/home/kambiz/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/figure.pyc in sca(self, a) 1196 def sca(self, a): 1197 'Set the current axes to be a and return a' -> 1198 self._axstack.bubble(a) 1199 for func in self._axobservers: func(self) 1200 return a

/home/kambiz/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/figure.pyc in bubble(self, a) 97 stack, to the top. 98 """ ---> 99 return Stack.bubble(self, self._entry_from_axes(a)) 100 101 def add(self, key, a):

/home/kambiz/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/figure.pyc in _entry_from_axes(self, e) 85 86 def _entry_from_axes(self, e): ---> 87 ind, k = dict([(a, (ind, k)) for (k, (ind, a)) in self._elements])[e] 88 return (k, (ind, e)) 89

KeyError: matplotlib.axes.AxesSubplot object at 0x56e401d0

Roman C
  • 49,761
  • 33
  • 66
  • 176
Kambiz
  • 685
  • 2
  • 8
  • 18
  • Are you referring to a notebook opened inside Canopy or externally? – punchagan Aug 06 '13 at 05:37
  • @punchagan I am referring to a notebook opened outside Canopy via `ipython --pylab=inline` in the terminal. I didn't know about a Notebook inside Canaopy! Should I be doing that? My assumption was that 'everything' is under Canopy. What concerns me is that there are two ipython version both under Canopy directories in different locations on the machine, as though there were two installations. – Kambiz Aug 06 '13 at 08:01
  • Getting different versions of IPython in the notebook started from outside Canopy and the shell inside Canopy shouldn't be anything alarming. Canopy uses virtual environments to allow users to install their own versions of packages, without forcing them to use the version the application depends on. The problem is else where. Can you post the code that doesn't run for you, to try and reproduce and debug the issue? – punchagan Aug 06 '13 at 10:34
  • @punchagan I will edit the post to include the code. Also note that it involves a little known third party class function with a plot method; from a (electrophysiological) data analysis module called mne-python. Thus, I am not sure how much we might glean from it. – Kambiz Aug 06 '13 at 17:48

0 Answers0