subplot aligment automatic method
Mostrar comentarios más antiguos
Hi,
I would like to know if there is an easy way to align subplots ina figure. Here is my problem.
I have a figure with a subplot with a colorbar (on the right of the plot) and a subplot without a colorbar but with two y axis and relative labels bennith it. I would like the plot to be aligned (meaning the x values of the two subplot should be at the same horizontal location). The only way I found to achive that is to thinker with the 'Position' options of the subplot. Like:
subplot(4,2,6,'Position', [0.095 0.1 0.81 0.1428])
But thsi solution depends on the size of the figure itself and on the screen the figure is beign plotted to (at least that is my guess since I get different results dependig on the screen matlab is plotting it in and if I maximize the figure or not).
minimal working example of the problem:
C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
figure
subplot(2,1,1)
imagesc(C)
colorbar
subplot(2,1,2)
hold on
yyaxis left
plot(C(:)); ylabel('C')
yyaxis right
plot(-C(:)); ylabel('-C')
Real case problem output

Any advice is appriciated!
4 comentarios
giacomo labbri
el 5 de Mzo. de 2021
Editada: giacomo labbri
el 5 de Mzo. de 2021
> I would like to understand why this is not working
It does work in the sense of equating axis sizes. It's similar to method 1 in my answer. The problem is the linkaxes line which changes the xlim property which has nothing to do with axis position within the figure.
giacomo labbri
el 7 de Mzo. de 2021
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Axes Appearance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


