File: ef230-2023-08/www/examples/plotting_background_image.m Download
% example of plotting with a background image
clear all; close all; clc;
 
% get the image
url='http://ef.engr.utk.edu/ef230/modules/matlab-images/Joe_Miner.jpg';
img=imread(url);
[h w c] = size(img); % get some info about the image

% set desired axis limits first to keep the plot from flipping
xmin=0; xmax=100; ymin=0; ymax=200;
axis([xmin,xmax,ymin,ymax]);
axis equal % makes the x and y axis the same size
hold on

% place the original image to cover the entire plot limits
% note the reversal of ymax and ymin - this flips the image to be correct
image([xmin xmax],[ymax ymin],img);

% now plot something 
t=linspace(0,2*pi,9); t=t+pi/8;
r=40; x0=50; y0=100;
x=x0+r.*cos(t);
y=y0+r.*sin(t);
plot(x,y,'r-','linewidth',4)