Plotting problem in Guide GUI

8 views (last 30 days)
Katie Pollock
Katie Pollock on 28 Jan 2014
Commented: Katie Pollock on 29 Jan 2014
Hi,
I'm having an issue getting my data to plot correctly in my GUIDE generated GUI. I have a main gui and a subgui which use the handles architecture. All the code I've written runs in the maingui, and part of it outputs charts and graphs in the subgui (which consists of only the GUIDE generated initialization code).
Currently, its outputting all the arrays in tables in the subgui correctly. I also have 2 axes, one that I want to display a scatterplot and one that I want to display a bar graph. The problem is that even when I call them by their tag, they both display on the same axes, and this axes is the last one created(I have tried deleting them and making new ones, it always plots on whichever axes I added to the gui most recently).
In the subgui:
1) I generated 2 separate axes
2) Changed their tags to: graph1_BestMemberEver and graph2_EmergingPopulation
3) Clicked in viewcallbacks to make CreateFcn callbacks for them in the subgui (GUIDE generated, I changed nothing)
Then, when I execute the following code in the main gui:
%Gets handles from the subgui with filename SubGUI_OUTPUT_DATA.m
subgui = SubGUI_OUTPUT_DATA;
subguihandles = guidata(SubGUI_OUTPUT_DATA);
guidata(subgui, subguihandles);
%Displays a [9x3 double] array of data (handles.output) in the subgui table
%with the tag OutputVectors correctly, this coding scheme works correctly
%for 6 other similar tables in the subgui
set (subguihandles.OutputVectors, 'data', handles.output);
%Should plot scatterplot into subgui axes with tag graph1_BestMemberEver
plotx1 = handles.CumulativeBestMemberOutput(:,1); %[2x1 double]
ploty1 = handles.CumulativeBestMemberOutput(:,end);%[2x1 double]
handles.scatter1 = scatter(plotx1, ploty1);
set (subguihandles.graph1_BestMemberEver, 'UserData', handles.scatter1);
%Should plot bar graph into subgui axes with tag graph2_EmergentPopulation
ploty2 = handles.recovery;%[18x1 double]
handles.bar1 = bar(ploty2);
set (subguihandles.graph2_EmergentPopulation, 'UserData', handles.bar1);
But, the way this currently runs, nothing plots in the axes with tag graph1_BestMemberEver, and the bar graph plots correctly. When you add a 'hold on' line of code right before the bar graph code, both the scatter plot and the bar graph plot in the axes with the tag graph2_EmergentPopulation. If you add a third axes with an unrelated tag, they both plot there.
I've read through quite a bit of advice online but nothing seems to address this problem. I read something that said to change the NextPlot property from replace to replacechildren and did this for both axes but it didn't change the result.

Answers (1)

Walter Roberson
Walter Roberson on 29 Jan 2014
  2 Comments
Katie Pollock
Katie Pollock on 29 Jan 2014
I made the following changes to my code based on your answer:
%Should plot scatterplot into subgui axes with tag graph1_BestMemberEver
plotx1 = handles.CumulativeBestMemberOutput(:,1); %[2x1 double]
ploty1 = handles.CumulativeBestMemberOutput(:,end);%[2x1 double]
handles.scatter1 = scatter(plotx1, ploty1);
graph1 = axes(subguihandles.graph1_BestMemberEver);
plot(graph1, handles.scatter1);
%set (subguihandles.graph1_BestMemberEver, 'UserData', handles.scatter1);
%Should plot bar graph into subgui axes with tag graph2_EmergentPopulation
ploty2 = handles.recovery;%[18x1 double]
handles.bar1 = bar(ploty2);
graph2 = axes(subguihandles.graph2_EmergentPopulation);
plot(graph2, handles.bar1);
%set (subguihandles.graph2_EmergentPopulation, 'UserData', handles.bar1);
Now it plots just the scatterplot on the second axes (graph2_EmergentPopulation) and doesn't plot the bar graph at all. This is the opposite problem from before. Did I follow the instructions in your link correctly? I'd really like this to plot in my subgui, but if I have to I can follow your code exactly to just make figures instead.
Katie Pollock
Katie Pollock on 29 Jan 2014
Thank you for your help, I figured out a fix after looking at more MATLAB answers online:
In Guide, I went to tools -> gui options -> and changed command line accessibility to 'on'. I think this was necessary because the subgui is being plotted from a callback that isn't actually inside its own code.
Then I added a line of code above each of my original set lines to make the appropriate axes current:
%Should plot scatterplot into subgui axes with tag graph1_BestMemberEver
plotx1 = handles.CumulativeBestMemberOutput(:,1); %[2x1 double]
ploty1 = handles.CumulativeBestMemberOutput(:,end);%[2x1 double]
handles.scatter1 = scatter(plotx1, ploty1);
axes(subguihandles.graph1_BestMemberEver);
set (subguihandles.graph1_BestMemberEver, 'UserData', handles.scatter1);
%Should plot bar graph into subgui axes with tag graph2_EmergentPopulation
ploty2 = handles.recovery;%[18x1 double]
handles.bar1 = bar(ploty2);
axes(subguihandles.graph2_EmergentPopulation);
set (subguihandles.graph2_EmergentPopulation, 'UserData', handles.bar1);
Now everything displays in its correct axes!

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!