Plotting on a map projection in Matlab

A couple of months back I was trying to figure out how to plot some data on a specific map projection in Matlab. It took me far more googling than should have been necessary, but I eventually go there, so here’s a little reminder to me:

If I have a set of sky positions with their right ascension (between 0 and 2π radians) held in ra and declination (between -π/2 and π/2 radians) held in dec then I could plot those points on a Hammer projection via:

% source RA
ra = 0.6;

% source declination
dec = -0.45;

% create figure
figure;

% create sky map using Hammer projection
axesm('MapProjection', 'hammer', 'AngleUnits', 'radians');

% plot point on sky
plotm(dec, ra, '.');

Or, if I have an image array imarr (for declination running over the first index and right ascension over the second), with points defined at right ascension ras and declination decs, then I could plot the image on the Hammer projection via:

axesm('MapProjection', 'hammer', 'AngleUnits', 'radians');
surfacem(decs, ras, imarr);

More information can be found in Matlab with: doc axesm, doc plotm and doc surfacem.

Leave a Reply