Create a plot with multiple axes on a uitab. Using addaxis
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gabriel Bischof
el 5 de Dic. de 2019
Comentada: Gabriel Bischof
el 6 de Dic. de 2019
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 comentario
Adam
el 5 de Dic. de 2019
Editada: Adam
el 5 de Dic. de 2019
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.
Respuesta aceptada
Max Murphy
el 5 de Dic. de 2019
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!