필터 지우기
필터 지우기

Create a plot with multiple axes on a uitab. Using addaxis

조회 수: 11 (최근 30일)
Gabriel Bischof
Gabriel Bischof 2019년 12월 5일
댓글: Gabriel Bischof 2019년 12월 6일
I have created a tabbed Panel, in this Panel i want to create a Plot with multiple axes. To do this I am working with "addaxis" from https://de.mathworks.com/matlabcentral/fileexchange/9016-addaxis.
My code:
obj.plot=axes('Parent', obj.tab, 'Position',[0.05, 0.15 , 0.92, 0.83], 'Units', 'normalized');
x = 0:.1:4*pi;
plot(x,sin(x));
addaxis(x,sin(x-pi/3));
addaxis(x,sin(x-pi/2),[-2 5],'linewidth',2);
addaxis(x,sin(x-pi/1.5),[-2 2],'v-','linewidth',2);
addaxis(x,5.3*sin(x-pi/1.3),':','linewidth',2);
addaxislabel(1,'one');
addaxislabel(2,'two');
addaxislabel(3,'three');
addaxislabel(4,'four');
addaxislabel(5,'five');
addaxisplot(x,sin(x-pi/2.3)+2,3,'--','linewidth',2);
addaxisplot(x,sin(x-pi/1),5,'--','linewidth',2);
legend('one','two','three','four','five','three-2','five-2');
But when i execute the code the axes are missing.
When i create a figure:
figure()
x = 0:.1:4*pi;
plot(x,sin(x));
addaxis(x,sin(x-pi/3));
addaxis(x,sin(x-pi/2),[-2 5],'linewidth',2);
addaxis(x,sin(x-pi/1.5),[-2 2],'v-','linewidth',2);
addaxis(x,5.3*sin(x-pi/1.3),':','linewidth',2);
addaxislabel(1,'one');
addaxislabel(2,'two');
addaxislabel(3,'three');
addaxislabel(4,'four');
addaxislabel(5,'five');
addaxisplot(x,sin(x-pi/2.3)+2,3,'--','linewidth',2);
addaxisplot(x,sin(x-pi/1),5,'--','linewidth',2);
legend('one','two','three','four','five','three-2','five-2');
everything is fine.
I added two screenshots.
when_figure.PNG
when_tab.PNG
  댓글 수: 1
Adam
Adam 2019년 12월 5일
편집: Adam 2019년 12월 5일
You would be best asking the author of the file exchange submission really as we don't know how it works without downloading the code and searching through it.
First thing that comes to mind, on a quick glance, is that addaxis does not take any parent argument, like most Mathworks plotting instructions do. This immediately raises alarm bells as I hate calling plotting instructions without giving an explicit parent for proper code. It may be that it is using gcf, in which case it is parenting it to the figure, rather than the tab. I don't know for sure, but since you are not telling it to add axis to the tab I would be surprised if it knows to do so since you also don't pass in the axes, for it to get the parent from that.
Does the varargin for the addaxis function support passing in a 'Parent' as a 'Name', 'Value' pair? Try:
addaxis(x,sin(x-pi/3), 'Parent', obj.tab );
and the same in the other cases, if it is supported.

댓글을 달려면 로그인하십시오.

채택된 답변

Max Murphy
Max Murphy 2019년 12월 5일
In the function addaxis (from FEX), at ~line 110 there is a call to the Matlab axes function:
h_ax = axes('position',[xpos, cpos(2), cpos(3)*.015, cpos(4)]);
Change it to:
h_ax = axes(cah.Parent,'position',[xpos, cpos(2), cpos(3)*.015, cpos(4)]);
My guess is that the default behavior causes the new axes lines to be created under the uitab object, so you don't see them.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by