6
$\begingroup$

I have a spike train. The data shows the time at which the neuron fired a spike. I want to plot them like this picture:

enter image description here

Here is the data for one spike train which corresponds to the one of the neurons in the figure above.

Download the spike train data

$\endgroup$
  • $\begingroup$ This can be done really easily. But your data are much larger than those on your plot. $\endgroup$ – Öskå Jul 25 '14 at 13:46
  • $\begingroup$ @Öskå I just put the data as a sample of the spike train in case it is needed. $\endgroup$ – MOON Jul 25 '14 at 14:19
7
$\begingroup$

Here is an example with some random data:

SeedRandom@0;
dat = Sort /@ RandomInteger[{200, 700}, {3, 25}];
Graphics[{Hue@.5, Opacity@.7, 
  MapIndexed[Line@Outer[List, #, 40 #2[[1]] + {20, -20}] &, dat]}, 
  Axes -> {True, True}, 
  Ticks -> {Automatic, Thread@{Range[40, 3*40, 40], Range@3}}]

Mathematica graphics

With your data, it's a different story and it looks like:

data = ToExpression@Import["http://pastebin.com/raw.php?i=Vj4nQNB5"];
Graphics[Line[{{Log@#, .5}, {Log@#, 1.5}}] & /@ data]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ You can replace your Table expression with: MapIndexed[Line @ Outer[List, #, 40 #2[[1]] + {20, -20}] &, dat] $\endgroup$ – Mr.Wizard Jul 25 '14 at 14:35
  • $\begingroup$ @Mr.Wizard Thanks! I knew that there was something but I just considered that Table was fast enough for this.. :) $\endgroup$ – Öskå Jul 25 '14 at 17:39
6
$\begingroup$

DistributionChart with ChartElementFunction->"LineDensity"

spktrnF[data_, opts : OptionsPattern[]] := 
   Module[{options = {ChartBaseStyle -> EdgeForm[None],
                      ChartElementFunction -> "LineDensity",
                      BarOrigin -> Left, BarSpacing -> 0.1,
                      ChartLabels -> Range[Length@data]}},
          DistributionChart[data, If[opts === {}, options, PrependTo[options, {opts}]]]]


SeedRandom@0;
dat = Sort /@ RandomInteger[{200, 700}, {5, 100}];

spktrnF[dat, ImageSize -> 800, AspectRatio -> 1/3, 
             ChartStyle -> "SolarColors", FrameStyle -> 16, 
             FrameLabel -> {"Time", "Neuron", None, None}]

enter image description here

$\endgroup$
4
$\begingroup$

You could use ArrayPlot.

t = Flatten @ Import["f:\\spikes.dat"];
p = ConstantArray[0, Max[t]];
p[[t]] = 1;
ArrayPlot[{p[[1 ;; 1000]], p[[1000 ;; 2000]]},
  AspectRatio -> 1/10,
  FrameTicks -> Automatic,
  FrameLabel -> {"neuron", "time"}]

enter image description here

But this approach is bad for data with more than 1000 time records

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.