Problem with second axis in subplot
8 次查看(过去 30 天)
显示 更早的评论
Hi all! I plot in a loop several graphs in the same subplot. Now I need a second x axis in the subplot.
figure(1)
HandleP1 = subplot(2, 2, 1, 'Parent', p);
hold on;
plot(n, CH2VS)
ax1 = gca % current axes
ax1.Visible = 'off'; %just to see is the second axis is hidden anywhere
ac12 = axes('Position',ax1.Position,'XAxisLocation','top','YAxisLocation','right','Color','none');
ax12 = gca;
ax12.Visible = 'on';
ax12pos = ax1.Position;
ax12.XLim = ax1.XLim;
In my opinion, these few lines should do the trick, with the second x axis on top of the subplot. But the axis is simply not visible.
Whats wrong?
Best regards, Thomas
6 个评论
Stephen23
2017-10-20
编辑:Stephen23
2017-10-20
As I wrote before, you need to specify the axes parent. Your code does not specify the axes parent, and so the second axes are created in the figure rather than in the uipanel. And thus the second axes are perfectly hidden under the uipanel, because you made them exactly the same size!
You need to do this:
axes(p, ...) % specify the parent as the first input argument!
instead of this:
axes(...)
which you are doing now. Have a look at your code where you create the axes.
Every time you create or access a graphics object you should always specify the handles explicitly. Do NOT rely on the current axes/figure/etc. as being the correct object that you need!
You did not specify the axes parent, and so it defaults to using the current figure as its parent.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!