Is it possible to display an image behind this plot?
thetaE= linspace(-pi,pi,1000); %E=Earth
thetaMC=linspace(-pi,pi,800); %MC=Mercury
thetaV=linspace(-pi,pi,900); %V=Venus
thetaM=linspace(-pi,pi,2000); %M=Mars
thetaJ=linspace(-pi,pi,3000); %J=Jupiter
thetaS=linspace(-pi,pi,5000); %Saturn
thetaU=linspace(-pi,pi,5800); %U=Uranus
thetaN=linspace(-pi,pi,10000); %N=Neptune
xSun=cos(thetaE); %Sun=Sun
ySun=sin(thetaE);
xMC=cos(thetaMC);
yMC=-sin(thetaMC);
xV=cos(thetaV);
yV=sin(thetaV);
xE=cos(thetaE);
yE=sin(thetaE);
xM=cos(thetaM);
yM=sin(thetaM);
xJ=cos(thetaJ);
yJ=sin(thetaJ);
xS=cos(thetaS);
yS=sin(thetaS);
xU=cos(thetaU);
yU=-sin(thetaU);
xN=cos(thetaN);
yN=sin(thetaN);
plot(xE,yE)
plot(19*xN,19*yN)
set(gca,'color','none')
hold on
pSun=plot(xSun(1),ySun(1),'o','MarkerSize',30,'MarkerFaceColor','y')
pMC=plot(4*xMC(1),4*yMC(1),'o','MarkerSize',3,'MarkerFaceColor','k')
pV= plot(6*xV(1),6*yV(1),'o','MarkerSize',4,'MarkerFaceColor','y')
pE= plot(8*xE(1),8*yE(1),'o','MarkerSize', 5,'MarkerFaceColor','b')
pM= plot((10*xM(1)),(10*yM(1)),'o','MarkerSize',3,'MarkerFaceColor','r')
pJ= plot((12*xJ(1)),(12*yJ(1)),'o','MarkerSize',15,'MarkerFaceColor','r')
pS= plot((14*xS(1)),(14*yS(1)),'o','MarkerSize',10,'MarkerFaceColor','y')
pU= plot((16*xU(1)),(16*yU(1)),'o','MarkerSize',9,'MarkerFaceColor','c')
pN= plot((18*xN(1)),(18*yN(1)),'o','MarkerSize',8,'MarkerFacecolor','b')
hold off
axis manual
for j = 1:length(thetaE)
for j = 1:length(thetaM)
pMC.XData=4*xMC(j);
pMC.YData=4*yMC(j);
pV.XData = 6*xV(j);
pV.YData = 6*yV(j);
pE.XData = 8*xE(j);
pE.YData = 8*yE(j);
pM.XData= 10*xM(j);
pM.YData= 10*yM(j);
pJ.XData= 12*xJ(j);
pJ.YData= 12*yJ(j);
pS.XData= 14*xS(j);
pS.YData= 14*yS(j);
pU.XData= 16*xU(j);
pU.YData= 16*yU(j);
pN.XData= 18*xN(j);
pN.YData= 18*yN(j);
drawnow
end
end

 Accepted Answer

KSSV
KSSV on 31 Mar 2017

9 Comments

Thanks! I was looking at this page before and could't get it to work with my plot, I'll try it again though and post what I get.
This is what I have now.
thetaE= linspace(-pi,pi,1000); %E=Earth
thetaMC=linspace(-pi,pi,800); %MC=Mercury
thetaV=linspace(-pi,pi,900); %V=Venus
thetaM=linspace(-pi,pi,2000); %M=Mars
thetaJ=linspace(-pi,pi,3000); %J=Jupiter
thetaS=linspace(-pi,pi,5000); %Saturn
thetaU=linspace(-pi,pi,5800); %U=Uranus
thetaN=linspace(-pi,pi,10000); %N=Neptune
xSun=cos(thetaE); %Sun=Sun
ySun=sin(thetaE);
xMC=cos(thetaMC);
yMC=-sin(thetaMC);
xV=cos(thetaV);
yV=sin(thetaV);
xE=cos(thetaE);
yE=sin(thetaE);
xM=cos(thetaM);
yM=sin(thetaM);
xJ=cos(thetaJ);
yJ=sin(thetaJ);
xS=cos(thetaS);
yS=sin(thetaS);
xU=cos(thetaU);
yU=-sin(thetaU);
xN=cos(thetaN);
yN=sin(thetaN);
plot(19*xN,19*yN,'Color','none')
set(gca,'color','none')
img = imread('StarBack.jpg');
% set the range of the axes
% The image will be stretched to this.
min_x = -19;
max_x = 19;
min_y = -19;
max_y = 19;
% make data to plot - just a line.
x = min_x:max_x;
y = (19/19)*x;
figure
imagesc(img);
xlabel('Raster Column');
ylabel('Raster Row');
colormap(gray);
imagesc([min_x max_x], [min_y max_y], flipim(img,1)
hold on
plot(x,y,'b-*','linewidth',1.5);
set(gca,'ydir','normal');
pSun=plot(xSun(1),ySun(1),'o','MarkerSize',30,'MarkerFaceColor','y')
pMC=plot(4*xMC(1),4*yMC(1),'o','MarkerSize',3,'MarkerFaceColor','k')
pV= plot(6*xV(1),6*yV(1),'o','MarkerSize',4,'MarkerFaceColor','y')
pE= plot(8*xE(1),8*yE(1),'o','MarkerSize', 5,'MarkerFaceColor','b')
pM= plot((10*xM(1)),(10*yM(1)),'o','MarkerSize',3,'MarkerFaceColor','r')
pJ= plot((12*xJ(1)),(12*yJ(1)),'o','MarkerSize',15,'MarkerFaceColor','r')
pS= plot((14*xS(1)),(14*yS(1)),'o','MarkerSize',10,'MarkerFaceColor','y')
pU= plot((16*xU(1)),(16*yU(1)),'o','MarkerSize',9,'MarkerFaceColor','c')
pN= plot((18*xN(1)),(18*yN(1)),'o','MarkerSize',8,'MarkerFacecolor','b')
hold off
axis manual
for j = 1:length(thetaE)
for j = 1:length(thetaM)
pMC.XData=4*xMC(j);
pMC.YData=4*yMC(j);
pV.XData = 6*xV(j);
pV.YData = 6*yV(j);
pE.XData = 8*xE(j);
pE.YData = 8*yE(j);
pM.XData= 10*xM(j);
pM.YData= 10*yM(j);
pJ.XData= 12*xJ(j);
pJ.YData= 12*yJ(j);
pS.XData= 14*xS(j);
pS.YData= 14*yS(j);
pU.XData= 16*xU(j);
pU.YData= 16*yU(j);
pN.XData= 18*xN(j);
pN.YData= 18*yN(j);
drawnow
end
end
It is working right?
no, with this my original plot doesn't even display, it just gives me an empty graph
I have tried with my image it was working....attach your said image...
I downloaded this picture. https://www.readytribe.com/wp-content/uploads/2015/09/BigdipISS.jpg
figure
imagesc(img);
xlabel('Raster Column');
ylabel('Raster Row');
colormap(gray);
imagesc([min_x max_x], [min_y max_y], flipim(img,1)
hold on
In this section of your code you plot one image and then plot another one which will simply replace it. Then you call hold on afterwards.
You really should start to use explicit axes handles though. It isn't the problem here, but implicit axes handles are horrible.
If you want a plot then give the specific axes you want to plot on to the plot command. Don't just rely on gca being the correct axes or gcf being the figure you think it is. It may work for you in many cases then one day it won't and you'll be confused why your plot appears on a different axes to what you expect.
hFig = figure; hAxes = axes( hFig );
imagesc( hFig, img );
hold( hAxes, 'on' )
...
is all nice and explicit, not only less likely to result in bugs, but also easier to read through and understand which axes things are on.
I got it to work, thanks KSSV!
Thanks for the tip Adam, I'm going to work on that now.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Asked:

on 31 Mar 2017

Answered:

on 17 Nov 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!