Create a plot with multiple axes on a uitab. Using addaxis
Show older comments
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.


1 Comment
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.
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!