Filter löschen
Filter löschen

How to create two "axes" plots in the same GUI?

1 Ansicht (letzte 30 Tage)
Abhay Aradhya
Abhay Aradhya am 8 Jun. 2017
Kommentiert: Adam am 9 Jun. 2017
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

Akzeptierte Antwort

Adam
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
Abhay Aradhya
Abhay Aradhya am 9 Jun. 2017
Bearbeitet: Abhay Aradhya am 9 Jun. 2017
Sorry my bad, the below is the exact code
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
I tried your suggestion as indicated in the code above but Matlab throws a "Invalid handle." error on the line marked by Plot3..!!
Is there a different syntax for "Plot3"?
Adam
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots 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!

Translated by