subplot disappearing after changing left edge position

15 visualizaciones (últimos 30 días)
Hi everyone, thanks for your help in advance.
I have the following code to generate a series of subplots (to animate some data).
num_plot = 3;
x0 = [0];
y0 = [0];
y1 = [0.1 0.2 0.3 0.4 0.5 0.4 0.3 0.2 0.1];
y2 = [0.2 0.4 0.6 0.7 0.8 0.7 0.6 0.4 0.2];
x3 = [-0.5 -0.4 -0.3 -0.2 0 0.2 0.3 0.4 0.5];
y3 = [0 0.1 0.2 0.3 0.4 0.3 0.2 0.1 0];
set(0, 'DefaultFigurePosition', [200, 100, 1500, 800]);
figure;
xi10 = 0.12;
yi10 = 0.10;
xi11 = -0.01;
yi11 = 0.10;
xi12 = 0.05;
yi12 = 0.13;
for k = 1: length(y1)
clf;
subplot(num_plot,1,1);
bar(y1(k), 'b');
axis off;
set(subplot(num_plot,1,1), 'Position', [xi10, yi10, 0.01, 0.2]);
axis([0.6, 1.2, 0, 2]);
subplot(num_plot,1,2);
barh(-y2(k), 'g');
axis off;
set(subplot(num_plot,1,2), 'Position', [xi11, yi11, 0.15, 0.01]);
axis([-2, 0, 0.9, 1.1]);
subplot(num_plot,1,3);
plot([x0, x3(k)], [y0, y3(k)],'r', 'LineWidth', 5);
axis off;
set(subplot(num_plot,1,3), 'Position', [xi12, yi12, 0.1, 0.1]);
axis([-1, 1, 0, 1]);
pause(0.75);
end;
Since the bar and the barh charts don't line up nicely, I tried to shift the position slightly by setting xi10 = 0.125. However doing so caused the bar chart to disappear. Does anyone know how the Positions of the left edges affect the subplots? More precisely, how should the left edges be defined so that both subplots show up? Thanks so much for your help!

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Ag. de 2013
One of the features of subplot() is that if there is an axis that would at all be "covered" by the calculated axis position, then the existing axis is deleted unless it would be in exactly the same position.
Therefore you should create all your subplot before repositioning them. Towards this end, remember that you can record the output from subplot() to give you the axis handle.
ax3 = subplot(num_plot,1,3);
plot(ax3, [x0, x3(k)], [y0, y3(k)],'r', 'LineWidth', 5);
axis(ax3, 'off');
axis(ax3, [-1, 1, 0, 1]);
and eventually when all of the plots have been created,
set(ax3, 'Position', [xi12, yi12, 0.1, 0.1])
  1 comentario
Tintin
Tintin el 27 de Ag. de 2013
Editada: Tintin el 27 de Ag. de 2013
Thanks so much for your quick response! I will try this right away! :)
Is there a way to apriori determine the (relative) Positions of the axes so that one set does not cover the other?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Discrete Data Plots 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!

Translated by