Customizing location of plot on figure

54 views (last 30 days)
How can I set a plot to be in the center of a figure, while controlling the width? The problem I ham having is that my heatmap is way too wide and aligned at the bottom left of the page. I want to force it to by 50% narrower. The height will change depending on the number of columns, so I dont want to edit the x, y, or height info.
positioning = get(gca, 'position');
set(gca, 'position', [positioning(1) positioning(2) positioning(3)/4 positioning(4)/2]) %x y width height
h2 = gcf;
set(h2, 'PaperPositionMode', 'auto');
set(h2, 'PaperOrientation', 'portrait');
set(h2, 'PaperUnits', 'inches', 'PaperPosition', [0, 0, 8.5, 11])

Accepted Answer

Adam Danz
Adam Danz on 28 Aug 2019
Here's how to reduce the width of an heatmap to 50% and to center it on the figure. If you only want to reduce it to 50% and not change its lateral position, skip the 2nd line of code.
h = heatmap(. . .); % get the heatmap handle
h.Position(1) = h.Position(1) + (h.Position(3)/4); % move so that it will be centered
h.Position(3) = h.Position(3)/2; % reduce width to 50%

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!