Tabbed plots removes my title and labels?

5 visualizaciones (últimos 30 días)
Tobias Jørgensen
Tobias Jørgensen el 31 de Mzo. de 2020
Comentada: Tobias Jørgensen el 3 de Abr. de 2020
I have created two figures which contains a new tab for each plot.
However only Figure2 contains "title" and "labels" on the plot and it also contains the "legend" which should have been on Figure1 - tab2.
Any suggestions why this happens?
Code and screenshots are attached.
figure_handles(1).mainfig = figure;
figure_handles(1).tabgroup = uitabgroup;
figure_handles(2).mainfig = figure;
figure_handles(2).tabgroup = uitabgroup;
% Fig1, tab1
newtab = uitab(figure_handles(1).tabgroup, 'Title', "tab1");
ax1 = axes(newtab);
plot(ax1,rand(1,100)*10,rand(1,100)*10);
title('FIG 1')
xlabel('X label')
ylabel('Y label')
% Fig2, tab1
newtab = uitab(figure_handles(2).tabgroup, 'Title', "tab1");
ax = axes(newtab);
plot(ax,rand(1,100)*10,rand(1,100)*10);
title('FIG 2')
xlabel('X label')
ylabel('Y label')
% Fig1, tab2 with legend
newtab = uitab(figure_handles(1).tabgroup, 'Title', "tab2");
ax3 = axes(newtab);
plot(ax3,rand(1,100)*10,rand(1,100)*10);
hold on
plot(ax3,rand(1,100)*10,rand(1,100)*10);
legend('1', '2')
title('FIG 1')
xlabel('X label')
ylabel('Y label')
hold off

Respuesta aceptada

Jyotsna Talluri
Jyotsna Talluri el 3 de Abr. de 2020
The issue is because you are not setting the xlabel,ylabel,title to particular axis or figure. These values are automatically set for the figure that is declared recently.Instead of declaring all the figures before ,you could modify your code as below
figure_handles(1).mainfig = figure;
figure_handles(1).tabgroup = uitabgroup;
% Fig1, tab1
newtab = uitab(figure_handles(1).tabgroup, 'Title', "tab1");
ax1 = axes(newtab);
plot(ax1,rand(1,100)*10,rand(1,100)*10);
title('FIG 1')
xlabel('X label')
ylabel('Y label')
% Fig1, tab2 with legend
newtab = uitab(figure_handles(1).tabgroup, 'Title', "tab2");
ax3 = axes(newtab);
plot(ax3,rand(1,100)*10,rand(1,100)*10);
hold on
plot(ax3,rand(1,100)*10,rand(1,100)*10);
legend('1', '2')
title('FIG 1')
xlabel('X label')
ylabel('Y label')
hold off
figure_handles(2).mainfig = figure;
figure_handles(2).tabgroup = uitabgroup;
% Fig2, tab1
newtab = uitab(figure_handles(2).tabgroup, 'Title', "tab1");
ax = axes(newtab);
plot(ax,rand(1,100)*10,rand(1,100)*10);
title('FIG 2')
xlabel('X label')
ylabel('Y label')
  1 comentario
Tobias Jørgensen
Tobias Jørgensen el 3 de Abr. de 2020
Thanks for the answer.
However there was a reason why the plots where made in the order they were in, as this is acctually just a simplified version of my full code.
However i fixed it by specifying my axes objects as you suggested as seen in the code below.
figure_handles(1).mainfig = figure;
figure_handles(1).tabgroup = uitabgroup;
figure_handles(2).mainfig = figure;
figure_handles(2).tabgroup = uitabgroup;
% Fig1, tab1
newtab = uitab(figure_handles(1).tabgroup, 'Title', "tab1");
ax1 = axes(newtab);
plot(ax1,rand(1,100)*10,rand(1,100)*10);
title(ax1, 'FIG 1')
xlabel(ax1, 'X label')
ylabel(ax1, 'Y label')
% Fig2, tab1
newtab = uitab(figure_handles(2).tabgroup, 'Title', "tab1");
ax = axes(newtab);
plot(ax,rand(1,100)*10,rand(1,100)*10);
title(ax, 'FIG 2')
xlabel(ax, 'X label')
ylabel(ax, 'Y label')
% Fig1, tab2 with legend
newtab = uitab(figure_handles(1).tabgroup, 'Title', "tab2");
ax3 = axes(newtab);
plot(ax3,rand(1,100)*10,rand(1,100)*10);
hold(ax3, 'on')
plot(ax3,rand(1,100)*10,rand(1,100)*10);
legend(ax3, '1', '2')
title(ax3, 'FIG 1')
xlabel(ax3, 'X label')
ylabel(ax3, 'Y label')
hold(ax3, 'off')

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by