Plotting on background image of GUI

I have to plot some data on an image. When I am doing this with GUI after loading image, the image disapperas.
Here is my code.
global varTrend
f = figure('Visible','on','Name','',...
'Menubar','none','Toolbar','none', 'Units', 'points','NumberTitle','off',...
'Position',[0,0,1366,768],'Resize','on','color',[127 127 127]./255); % window
GazePanel = uipanel('Parent',f,'HandleVisibility','callback','Units','normalized' ...
,'Position',[0 0 1 1],'BackgroundColor',[127 127 127]./255); % Panel within the window
varTrend = axes('Parent',GazePanel,'HandleVisibility','callback', ...
'NextPlot','replacechildren','Units','points','Position', ...
[0,0,1366,768],'FontSize',8,'Color',[127 127 127]./255); % Axis within the window
imshow('D:\GUI.png','Parent',varTrend); % show the image
% This code is doing plotting on varTrend axis
count = 1;
for i=1:length(x_coordinate(1:300))
for j = 1:length(AOI_each)
if (x_coordinate(i)>=AOI_each(j,1)&&x_coordinate(i)<=AOI_each(j,2)&& ...
y_coordinate(i)>=AOI_each(j,3)&&y_coordinate(i)<=AOI_each(j,4));
AOI(i)=j;
if i ~=1
if AOI(i)~=0
saccade = i -1;
if AOI(i-1) ==0
idx = max(find(AOI(1:i) ~=0));
saccade = idx;
end
% giving weightage to each AOI
if AOI(i-1) == AOI(i)
count = count + 1;
scatter(varTrend,AOI_centroid(j,1),AOI_centroid(j,2),count*20,'filled','r')
hold on
end
if AOI(i-1) ~= AOI(i)
count = 1;
scatter(AOI_centroid(j,1),AOI_centroid(j,2),600,'filled','r')
hold on
plot(varTrend,[AOI_centroid(AOI(saccade),1) AOI_centroid(AOI(i),1)], ...
[AOI_centroid(AOI(saccade),2) AOI_centroid(AOI(i),2)],'-r','LineWidth',2)
end
xlim([0 1920])
ylim([0 1080])
pause(0.0001)%drawnow
hold on
else
break;
end
end
end
end
end

Answers (1)

Of course we can't run your image for several reasons but I'm guessing is that you called scatter() or plot() before "hold on" was applied. Try calling hold on immediately after imshow():
imshow('D:\GUI.png', [], 'Parent',varTrend); % Show the image
hold on;

6 Comments

Shows error
Error using images.internal.imageDisplayParsePVPairs (line 72)
The parameter, E:\aatif\D_DriveBackup\data\before24june\GUI.png, is not recognized by imageDisplayParsePVPairs
If I remove the null symbol from your code, it opens the image on GUI but did not plot on the image.
imshow('E:\aatif\D_DriveBackup\data\before24june\GUI.png','Parent',varTrend);
hold on;
There is another problem also, I am trying to plot scatters on GUI without image. But the plot only shows one point. I am tring to plot it continuously using drawnow. Here is my complete code. As a summary, there are two problems one is that the plot is not onm image and another with the scatter part, it do not shows plots continuously. It shows only one point on the GUI.
The overall objective is that to plot x and y continuously which will be received continuously from python and want to plot it on MATLAB GUI. Please help with this.
global varTrend
f = figure('Visible','on','Name','',...
'Menubar','none','Toolbar','none', 'Units', 'points','NumberTitle','off',...
'Position',[0,0,1920,1080],'Resize','on','color',[127 127 127]./255); % window
GazePanel = uipanel('Parent',f,'HandleVisibility','callback','Units','normalized' ...
,'Position',[0 0 1 1],'BackgroundColor',[127 127 127]./255); % Panel within the window
varTrend = axes('Parent',GazePanel,'HandleVisibility','callback', ...
'NextPlot','replacechildren','Units','points','Position', ...
[0,0,1920,1080],'FontSize',8,'Color',[127 127 127]./255); % Axis within the window
imshow('E:\aatif\D_DriveBackup\data\before24june\GUI.png','Parent',varTrend);
%imshow('E:\aatif\D_DriveBackup\data\before24june\GUI.png', [], 'Parent',varTrend); % Show the image
hold on;
for i = 1:100
scatter(varTrend,x_coordinate(i),y_coordinate(i),400)
xlim([0 1920])
ylim([0 1080])
drawnow
hold on
end
That's not the error we get. The error we get is:
Error using images.internal.getImageFromFile (line 13)
Cannot find the specified file: "E:\aatif\D_DriveBackup\data\before24june\GUI.png".
Why do you think we get that we get that error? Do you see any way we can avoid getting that error so we can do on to get the error that you get?
If I replace your image with the standard peppers.png demo image I get this:
Unrecognized function or variable 'x_coordinate'.
Error in test6 (line 17)
scatter(varTrend,x_coordinate(i),y_coordinate(i),400)
I'll check back later tonight.
This runs without error but I don't really know what you're planning
close all;
clear vars
clear global
global varTrend
f = figure('Visible','on','Name','',...
'Menubar','none','Toolbar','none', 'NumberTitle','off',...
'Resize','on','color',[127 127 127]./255); % window
GazePanel = uipanel('Parent',f,'HandleVisibility','callback','Units','normalized' ...
,'Position',[0 0 1 1],'BackgroundColor',[127 127 127]./255); % Panel within the window
varTrend = axes('Parent',GazePanel,'HandleVisibility','callback', ...
'NextPlot','replacechildren','Units','points','Position', ...
[0,0,1920,1080],'FontSize',8,'Color',[127 127 127]./255); % Axis within the window
f.WindowState = 'maximized';
rgbImage = imread('peppers.png');
[rows, columns, numColorChannels] = size(rgbImage)
imshow(rgbImage, 'Parent',varTrend);
axis('on', 'image');
%imshow('E:\aatif\D_DriveBackup\data\before24june\GUI.png', [], 'Parent',varTrend); % Show the image
hold on;
x_coordinate = columns * rand(1, 100);
y_coordinate = rows * rand(1, 100);
plot(varTrend, x_coordinate, y_coordinate, '.', 'markerSize', 40)
xlim([0 1920])
ylim([0 1080])
drawnow
hold off
Thanks a lot. It is working now. The only problem is that the data is not plotted on the image. I have attached the the GUI. You can see that the image is not in the background of the data. I want that the data should appear over the image.
What is the gaze panel for? Why not just simply call imshow, hold on, then plot or scatter? Why are you doing all kinds of special, fancy stuff wtih the controls?
Ok Thanks a lot for continuous guidance. I will remove the fancy stuffs.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!