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

11 次查看(过去 30 天)
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