Raster plots and MATLAB

A colleague once told me: “in MATLAB, drawing a raster plot is a trivial, one line command”. True, but then you spend another 10 lines of code trying to make it not look like complete crap. Which is both time consuming and futile. In the end, you know you’re going to be spending half a day with Adobe Illustrator to fix it. But it does all start with one line of code.

Here’s some code to draw simple, one line raster plots:

function raster(in)
if size(in,1) > size(in,2)
    in=in';
end
axis([0 max(in)+1 -1 2])
plot([in;in],[ones(size(in));zeros(size(in))],'k-')
set(gca,'TickDir','out') % draw the tick marks on the outside
set(gca,'YTick', []) % don't draw y-axis ticks
set(gca,'PlotBoxAspectRatio',[1 0.05 1]) % short and wide
set(gca,'Color',get(gcf,'Color')) % match figure background
set(gca,'YColor',get(gcf,'Color')) % hide the y axis
box off

As an aside…

Looking for a wry take on MATLAB’s shortcomings from an anonymous neuroscientist? Try Abandon MATLAB. This blog’s posts include these gems:
Matlab doesn’t know how to draw one ball out of an urn containing one ball
The Mathworks don’t even know how to look up functions in their own global namespace
And this image (source):

Tags: