Image Example

Using images in matlab plots can offer some advantages as the pixel graphics is highly compressed. The axis elements are still vector elements. This combination is good for publications as font styles and labels can be reworked at any time.

For the following example we use topology data from the NASA Shuttle Radar Topography Mission (SRTM) project ( The height data is stored as signed 16bit integer as a 1201 × 1201 matrix. The topology height files can be found in

function demo_plot2svg_image
% Read in topology data
all_data = read_topo('N47E007.hgt');
xax = linspace(7,8,size(all_data,1));
yax = linspace(47,48,size(all_data,2));
% Draw the image
% Change tickmarks to degree and minutes
grid on
box on
% Create some axis labels
title('Topography North of Switzerland')
% Force equal scaling of x and y
axis equal
axis tight
% Call plot2svg to create the SVG plot

function data = read_topo(name)
% Open the file in big-endian mode
fid = fopen([name '/' name],'r','b');
% Read signed 16bit data
data = fread(fid,1201*1201,'short=>short');
% Reformat to matrix
data = reshape(data,1201,1201)';
% Remove overlap
data = data(1:end - 1, 1:end - 1);
% Convert to double (most function can only handle double)
data = double(data);
% Remove missing data points by NaNs
data(data == -32768) = NaN;

function label = convert_to_deg(data)
deg = floor(data);
minutes = (data - deg) .* 60;
for i = 1:length(deg)
label{i} = [num2str(deg(i)) '°' num2str(minutes(i)) ''''];

Plot Result of the Image Example

The SVG plot includes two links to pixel graphics PNG files. The first one is the map. The second one is the color bar contents. The axis and labels are vector elements. Loading the plot into a SVG editor like e.g. Inkscape allows for modifications. Axis and figure contents are grouped. In order to modify single figure elements the groups have to be dissolved. The plot2svg function draws always a background to define the figure size. This is visible in the image below by the white background. In this case the background would not be needed. Loading the figure in Inkscape, ungrouping the elements, and removing the background is very simple.

Pixelgraphics of the SVG Plot.

View the SVG plot