How to create two "axes" plots in the same GUI?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
customUserInterface = figure('Name','Solution selector window');
ax = axes('Parent',customUserInterface,'Position',[.1 .5 .375 .4]);
subplot(ceil(sqrt(size(sectors_all,1))),ceil(sqrt(size(sectors_all,1))),p, 'Position',[.1 .5 .375 .4]);
hold on
for m=1:numOfAP
plot3(ax,Data(m).traj(:,1),Data(m).traj(:,2),Data(m).traj(:,3),'g','LineWidth',2)
hold on
grid on
end
hold on
ab = axes('Parent',customUserInterface,'Position',[.525 .5 .375 .4]);
subplot(ceil(sqrt(size(sectors_all,1))),ceil(sqrt(size(sectors_all,1))),p, 'Position',[.525 .5 .375 .4]);
hold on
for m=1:numOfAP
plot3(ab,Data(m).traj(:,1),Data(m).traj(:,2),Data(m).traj(:,3),'g','LineWidth',2)
hold on
grid on
end
hold on
In this case it only plots the 2nd axes..!!
Please suggest me a better way to do this. Thanks in advance
0 Kommentare
Akzeptierte Antwort
Adam
am 8 Jun. 2017
You haven't shown any plotting code so I can only guess at what you are doing which is a bit silly if you are trying to get an answer to a question! I suspect you are just doing what too many people do and something to the effect of just
plot( xData, yData );
If you look at the documentation:
doc plot
you will see
plot(ax,___)
as an option. This syntax works exactly as your (presumed) current syntax, but you give it the axes handle onto which to plot as the first argument. This is far better than just relying on whatever the current axes happens to be which is what the first syntax does.
2 Kommentare
Adam
am 9 Jun. 2017
What is that subplot call supposed to be doing? subplot creates axes, but you are creating your own axes so why use subplot after that? Either use subplot or create your own axes.
Again though with subplot, it returns a handle to the axes it creates. Store this and use it, in plot instructions and in hold, grid and any other instructions that you expect to be applied to a single axes.
You have six
hold on
instructions in that code, and that isn't counting the number of times the instructions inside the for loop get called. Just set
hold( ax, 'on' )
once. Throwing in more and more 'hold on' instructions and leaving them all in when they don't work just leads to overly messy code.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!