Ticket #20 (closed defect: fixed)

Opened 20 months ago

Last modified 19 months ago

Cannot easily plot AnalogSignal

Reported by: jnowacki Owned by: somebody
Priority: major Milestone: 0.2
Component: core Keywords:
Cc:

Description (last modified by apdavison) (diff)

The bug I've found was that I cannot plot easily analogue signals. Namely, if array provided to matplotlib is 1d (ndim = 1), then it tries to change it into a column vector. It does that by using newaxis. Let say that we have vector v, which v.shape = (n,), then to get column vector we do vc = v[:,newaxis], which is, in fact equivalent to vc = v[:,None]. Both numpy and quantities sorts this out well, but not neo's BaseAnalogSignal. It doesn't know how to handle None correctly and throws an exception, namely, that method i.start does not exist. I've attached a patch that solves it for me. I'm not sure it is the most elegant way, but when v[:,None] is called, the i in __getitem__(i) is a tuple, usually i = (slice(None, None, None), None). I went around it and delegate the job back to quantities, which works as I've checked. If you have other ways of dealing with that, please feel free to change it, but it has to be addressed in my opinion. A workaround without modifying the code is to cast BaseAnalogSignal to numpy array and then plot it.

Attachments

fix_analogsignal_getitem.diff Download (0.7 KB) - added by jnowacki 20 months ago.
fix_analogsignal_getitem2.diff Download (0.8 KB) - added by apdavison 20 months ago.
improved patch

Change History

Changed 20 months ago by jnowacki

Changed 20 months ago by apdavison

  • description modified (diff)

Changed 20 months ago by apdavison

  • description modified (diff)

Changed 20 months ago by apdavison

improved patch

Changed 20 months ago by apdavison

  • status changed from new to closed
  • resolution set to fixed

Hi Jakub,

Thanks very much for the patch. I have modified it a bit, so that now v[:, newaxis] returns an AnalogSignal rather than a quantities array. This can still be plotted, and preserves the metadata, although possibly it should be called something other than AnalogSignal since it is now a 2D array (albeit the second dimension has size 1).

I've applied this modified patch in r305

Changed 19 months ago by sgarcia

  • milestone set to 0.2
Note: See TracTickets for help on using tickets.