Trying to increase the maximum width of OuterPosition (plot is cut off)
Afficher commentaires plus anciens
I have the following code
f = figure();
f.Units = "inches";
f.OuterPosition = [0 0 7 2.5]
ax1 = axes(f,'Units','inches','Position',[0.25 0.25 2 2], ...
'XGrid','on','YGrid','on');
ax2 = axes(f,'Units','inches','Position',[2.5 0.25 2 2], ...
'XGrid','on','YGrid','on');
ax3= axes(f,'Units','inches','Position',[4.75 0.25 2 2], ...
'XGrid','on','YGrid','on');
plot(ax1,[0 1 2 3],[0 1 2 3])
ylabel("$y$","Interpreter","latex")
xlabel("$x$","Interpreter","latex")
plot(ax2,[0 1 2 3],[0 -1 -2 -3])
ylabel("$y$","Interpreter","latex")
xlabel("$x$","Interpreter","latex")
plot(ax3,[0 1 2 3],[0 1 2 3].^2)
ylabel("$y$","Interpreter","latex")
xlabel("$x$","Interpreter","latex")
When it produces a the plots, they're all cut off. I want the images to be to scale for a paper, hence why the width is 7". It seems that MATLAB is enforcing some hard limit on the maximum width it will allow for plotting, is there any way around this?
7 commentaires
Voss
le 12 Mar 2024
Note that Position is [x y width height] not [xmin ymin xmax ymax]. One reason the plots are cut off is that the axes' positions you have specified make the axes overlap. For instance, ax2 has its left side at x=2.5 inches and a width of 4.5 inches, which means its right side is at x=7 inches, overlapping with ax3, whose left side is at x=4.75 inches.
David Gillcrist
le 12 Mar 2024
Voss
le 12 Mar 2024
A figure's OuterPosition includes the title bar and border (if any) drawn by the operating system as well as any tool bars and menu bars created by MATLAB. Maybe setting the figure's InnerPosition (or Position, which is the same as InnerPosition for a figure) produces the right result?
Voss
le 12 Mar 2024
Also, note that the xlabel and ylabel calls are all applied to ax3 (which is the figure's CurrentAxes by default since it is the most recently created). Plotting into a specific axes does not by itself make that axes the CurrentAxes.
I imagine the intent was:
plot(ax1,[0 1 2 3],[0 1 2 3])
ylabel(ax1,"$y$","Interpreter","latex")
xlabel(ax1,"$x$","Interpreter","latex")
plot(ax2,[0 1 2 3],[0 -1 -2 -3])
ylabel(ax2,"$y$","Interpreter","latex")
xlabel(ax2,"$x$","Interpreter","latex")
plot(ax3,[0 1 2 3],[0 1 2 3].^2)
ylabel(ax3,"$y$","Interpreter","latex")
xlabel(ax3,"$x$","Interpreter","latex")
David Gillcrist
le 13 Mar 2024
Voss
le 13 Mar 2024
@David Gillcrist: Did you try setting the figure's Position rather than OuterPosition (as I mentioned here), and did that fix the problem?
David Gillcrist
le 13 Mar 2024
Réponses (0)
Catégories
En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
