{"id":3543,"date":"2025-12-08T09:39:13","date_gmt":"2025-12-08T14:39:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/?p=3543"},"modified":"2026-01-30T11:36:49","modified_gmt":"2026-01-30T16:36:49","slug":"advanced-control-of-size-and-layout-of-exported-graphics","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2025\/12\/08\/advanced-control-of-size-and-layout-of-exported-graphics\/","title":{"rendered":"Advanced Control of Size and Layout of Exported Graphics"},"content":{"rendered":"&nbsp;\r\n<table style=\"background-color: #e2f0ff\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 120px;padding: 3px;vertical-align: middle\"><img decoding=\"async\" class=\"aligncenter size-medium\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/LeiaRich.jpg\" alt=\"Portrait of Leia Rich\" \/><\/td>\r\n<td style=\"vertical-align: middle;padding: 3px\"><strong>Guest Writer: <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/25485576\" target=\"_blank\" rel=\"noopener\">Leia Rich<\/a>\r\n<\/strong>Leia is a software engineer on the MATLAB Charting Team. She first joined MathWorks as part of the Engineering Development Group (EDG) in 2022, and later became a developer contributing to the graphics infrastructure area and exporting. Outside of MathWorks, Leia enjoys traveling and photography.<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n\r\n<hr \/>\r\n\r\n<a href=\"https:\/\/matlab.mathworks.com\/open\/github\/v1?repo=MATLAB-Graphics-and-App-Building\/matlab-gaab-blog-2025&amp;file=exportgraphicsSizeLayout\/exportgraphics_size_layout.mlx\" target=\"_blank\" rel=\"nofollow noopener\"><img decoding=\"async\" class=\"\" src=\"https:\/\/www.mathworks.com\/images\/responsive\/global\/open-in-matlab-online.svg\" alt=\"Open in MATLAB Online\" \/><\/a>\r\n<div class=\"rtcContent\">\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Have you ever wanted to export your graphics and wished there was an easy way to specify the output size without having to adjust <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/matlab.ui.figure.html#mw_0ce70097-ec19-4cb1-98d9-f63f320a6f31\" target=\"_blank\" rel=\"noopener\"><span style=\"font-family: monospace\">Paper<\/span> properties<\/a> on the figure for <span style=\"font-family: monospace\">print<\/span> or use <span style=\"font-family: monospace\">tiledlayout<\/span>?<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Well now there's an easier way with new name-value pairs available for MATLAB Desktop and MATLAB Online in R2025a. Let's take a look at some of these changes to the exporting functions by using a plot of some exercise data that I collected when walking and running.<\/div>\r\nDownload <a href=\"https:\/\/github.com\/MATLAB-Graphics-and-App-Building\/matlab-gaab-blog-2025\/raw\/301f7d78219823c76d69b9016f21b2ac2de9f715\/exportgraphicsSizeLayout\/distanceAndHeartRateTables.mat\" target=\"_blank\" rel=\"noopener\">distanceAndHeartRateTables.mat<\/a>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">load(<span style=\"color: #a709f5\">\"distanceAndHeartRateTables.mat\"<\/span>)<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">scatter(walkTbl, <span style=\"color: #a709f5\">\"Distance\"<\/span>, <span style=\"color: #a709f5\">\"AvgHeartRate\"<\/span>, <span style=\"color: #a709f5\">\"filled\",<\/span> <span style=\"color: #a709f5\">\"DisplayName\"<\/span>, <span style=\"color: #a709f5\">\"Walking\"<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">hold on<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">scatter(runTbl, \"<span style=\"color: #a709f5\">Distance\"<\/span>, <span style=\"color: #a709f5\">\"AvgHeartRate\"<\/span>, <span style=\"color: #a709f5\">\"DisplayName\"<\/span>, <span style=\"color: #a709f5\">\"Running\"<\/span>);<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">xlabel(<span style=\"color: #a709f5\">'Distance (m)'<\/span>)<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">ylabel(<span style=\"color: #a709f5\">'Average Heart Rate (bpm)'<\/span>)<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">legend(Location=<span style=\"color: #a709f5\">'northeast'<\/span>)<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 495px;height: 334px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_1.png\" alt=\"\" width=\"495\" height=\"334\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">There's no surprise that running resulted in a higher heart rate. Let's use this plot to dive into new ways to control the output size of your exported graphics.<\/div>\r\n<h2 style=\"margin: 3px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\">Old way to specify size using <span style=\"font-family: monospace\">print<\/span><\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">One of the ways to specify the exported size that you may be familiar with is by adjusting the <span style=\"font-family: monospace\">Paper<\/span> properties on the figure. For example, if we want to print to a SVG file with a 5 inch width and 5 inch height, we can set the <span style=\"font-family: monospace\">PaperUnits<\/span> to <span style=\"font-family: monospace\">'inches'<\/span> then set the width and height on the <span style=\"font-family: monospace\">PaperPosition<\/span> both to 5.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px 4px 0px 0px;padding: 6px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">set(gcf,<span style=\"color: #a709f5\">'PaperUnits'<\/span>,<span style=\"color: #a709f5\">'inches'<\/span>)<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px;padding: 0px 45px 0px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">set(gcf,<span style=\"color: #a709f5\">'PaperPosition'<\/span>,[0 0 5 5])<\/div>\r\n<\/div>\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 0px 0px 4px 4px;padding: 0px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">print(gcf, <span style=\"color: #a709f5\">'printToSVG.svg'<\/span>, <span style=\"color: #a709f5\">'-dsvg'<\/span>)<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">The resulting SVG file looks like the image below, with the width and height both being 5 inches. The dashed line indicates the edge of the SVG file. Changing the <span style=\"font-family: monospace\">PaperPosition<\/span> changes the output size when using <span style=\"font-family: monospace\">print<\/span>, however, this does not impact the output when using <span style=\"font-family: monospace\">exportgraphics<\/span>. Below, we'll explore the new name-value pairs that allow you greater control of the output size when exporting.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 480px;height: 480px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_2.png\" alt=\"\" width=\"480\" height=\"480\" \/><\/div>\r\n<h2 style=\"margin: 20px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\">New way to specify size using <span style=\"font-family: monospace\">exportgraphics<\/span><\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Let's do an initial export of this plot using <span style=\"font-family: monospace\">exportgraphics<\/span>. Let's export it to SVG since <span style=\"font-family: monospace\">exportgraphics<\/span> supports this format starting in R2025a. We'll specify a background color when exporting so it is easier to compare the full output size.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf,<span style=\"color: #a709f5\">'exportToSVG.svg'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">This is what the resulting SVG file will look like:<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 501px;height: 321px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_3.png\" alt=\"\" width=\"501\" height=\"321\" \/><\/div>\r\n<h3 style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\">Specifying export size<\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">The output matches the aspect ratio of the original figure, but it does not have the dimensions that we want. If we want to get a square output, we can specify the width and height of the SVG file using the <span style=\"font-family: monospace\">Width<\/span>, <span style=\"font-family: monospace\">Height<\/span>, and <span style=\"font-family: monospace\">Units<\/span> name-value pairs.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf,<span style=\"color: #a709f5\">'exportToSVGSquare.svg'<\/span>,Width=5, Height=5, Units=<span style=\"color: #a709f5\">'inches'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Looking at the SVG output below, you'll notice it looks similar to what we got using <span style=\"font-family: monospace\">print<\/span> with the <span style=\"font-family: monospace\">Paper<\/span> properties set on the figure. Both outputs have overall sizes of 5 inches by 5 inches, however, the padding between the axes and the edges of the SVG file is less when using <span style=\"font-family: monospace\">exportgraphics.<\/span> <span style=\"font-family: monospace\">exportgraphics<\/span> by default exports using <span style=\"font-family: monospace\">'tight'<\/span> padding. <span style=\"font-family: monospace\">Padding<\/span> is one of the new name-value arguments, which allows you to specify the amount of space between the outer edge and the outside of the decorations. Let's explore this name-value argument next.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 480px;height: 480px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_4.png\" alt=\"\" width=\"480\" height=\"480\" \/><\/div>\r\n<h3 style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\">Adjusting the padding around the export<\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Let's try adjusting the padding to match the output we got using <span style=\"font-family: monospace\">print<\/span> more closely. This can be done by setting the <span style=\"font-family: monospace\">Padding<\/span> to <span style=\"font-family: monospace\">'figure'<\/span>, which includes the same relative amount of padding that appears in the figure window.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf, <span style=\"color: #a709f5\">'exportToSVGFigurePaddingSizeSpecified.svg'<\/span>, Padding=<span style=\"color: #a709f5\">'figure'<\/span>, Width=5, Height=5, Units=<span style=\"color: #a709f5\">'inches'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 480px;height: 480px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_5.png\" alt=\"\" width=\"480\" height=\"480\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">You can also adjust the padding without specifying a <span style=\"font-family: monospace\">Width<\/span> or <span style=\"font-family: monospace\">Height<\/span>.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf, <span style=\"color: #a709f5\">'exportToSVGFigurePaddingSpecified.svg'<\/span>, Padding=<span style=\"color: #a709f5\">'figure'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">This syntax preserves the amount of padding that we see in the figure window.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 560px;height: 337px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_6.png\" alt=\"\" width=\"560\" height=\"337\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span style=\"font-weight: bold\">What if you want a specific amount of padding around all 4 sizes?<\/span> You can specify a numeric value for the padding too. The <span style=\"font-family: monospace\">Units<\/span> name-value pair that we have used for the <span style=\"font-family: monospace\">Width<\/span> and <span style=\"font-family: monospace\">Height<\/span> previously is also used for <span style=\"font-family: monospace\">Padding<\/span>. Let's try adding 1 inch of padding around each side.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf, <span style=\"color: #a709f5\">'exportToSVGPaddingSpecified.svg'<\/span>, Padding=1, Units=<span style=\"color: #a709f5\">'inches'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 689px;height: 509px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_7.png\" alt=\"\" width=\"689\" height=\"509\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\"><span style=\"font-weight: bold\">When specifying both the size and padding<\/span>, the padding is included in the overall requested size. So if we specify an output size of 5 inches by 5 inches, and we also want 1 inch of padding, the padding is included inside the 5 inch by 5 inch output.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf, <span style=\"color: #a709f5\">'exportToSVGPaddingSizeSpecified.svg'<\/span>, Padding=1, Width=5, Height=5, Units=<span style=\"color: #a709f5\">'inches'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<h3 style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\"><\/h3>\r\n<h3 style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 480px;height: 480px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_8.png\" alt=\"\" width=\"480\" height=\"480\" \/><\/h3>\r\n<h3 style=\"margin: 15px 10px 5px 4px;padding: 0px;line-height: 20.4px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 17px;font-weight: bold;text-align: left\">Preserving onscreen aspect ratio when specifying size<\/h3>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">When specifying an output size, you might want the aspect ratio to be the same as what is seen in the figure window. We can maintain the original aspect ratio by specifying the name-value pair <span style=\"font-family: monospace\">PreserveAspectRatio<\/span> to be <span style=\"font-family: monospace\">'on'<\/span>. This will make it so that the output size is the requested 5 by 5 inches, but with extra padding added to the top and bottom to preserve the aspect ratio.<\/div>\r\n<div style=\"background-color: #f5f5f5;margin: 10px 15px 10px 0;min-width: 100%\">\r\n<div class=\"inlineWrapper\">\r\n<div style=\"border-radius: 4px;padding: 6px 45px 4px 13px;line-height: 18.004px;min-height: 0px;font-family: Menlo, Monaco, Consolas, 'Courier New', monospace, Menlo, Monaco, Consolas, 'Courier New', monospace;font-size: 14px\">exportgraphics(gcf, <span style=\"color: #a709f5\">'exportToSVGPreserveAspect.svg'<\/span>, Width=5, Height=5, Units=<span style=\"color: #a709f5\">'inches'<\/span>, PreserveAspectRatio=<span style=\"color: #a709f5\">'on'<\/span>, BackgroundColor=[0.53 0.808 0.98])<\/div>\r\n<\/div>\r\n<\/div>\r\n<div style=\"margin: 10px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 480px;height: 480px\" src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_9.png\" alt=\"\" width=\"480\" height=\"480\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">These new name-value pairs are also available for <span style=\"font-family: monospace\">copygraphics<\/span>, allowing you to easily specify the dimensions and padding when copying to clipboard.<\/div>\r\n<h2 style=\"margin: 20px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\">Using dialogs and Copy Figure settings<\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Now if you would rather use the export dialog so you can see how your output will look beforehand, you can specify these name-value pairs there too! Using the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/uiexportdlg.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-family: monospace\">uiexportdlg<\/span><\/a>, you can specify the width and height, as well as the aspect ratio. This is what the export dialog looks like when we open it up for the figure:<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 831px;height: 649px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_10.png\" alt=\"\" width=\"831\" height=\"649\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Now if we want to update the settings, we can see it reflected in the preview for the export. Let's use the same 5 inch by 5 inch output size that we have been using and set the background color to light blue before exporting it to SVG. The <span style=\"font-family: monospace\">uiexportdlg<\/span> will update to look like the below image:<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 831px;height: 648px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_11.png\" alt=\"\" width=\"831\" height=\"648\" \/><\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">As mentioned earlier, these options are available also for <span style=\"font-family: monospace\">copygraphics<\/span>. If instead of using the <span style=\"font-family: monospace\">copygraphics<\/span> command you want to use the Copy Figure option on the figure toolstrip, you can navigate to the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/creating_plots\/copy-figure-to-clipboard-from-edit-menu.html\" target=\"_blank\" rel=\"noopener\">Figure Copy Settings<\/a>. With these settings, you are able to specify the size and if you want to preserve the aspect ratio. These settings will be used if you press Copy Figure in the figure toolstrip.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: center\"><img decoding=\"async\" loading=\"lazy\" class=\"imageNode\" style=\"vertical-align: baseline;width: 806px;height: 587px\" src=\"http:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_12.png\" alt=\"\" width=\"806\" height=\"587\" \/><\/div>\r\n<h2 style=\"margin: 20px 10px 5px 4px;padding: 0px;line-height: 25px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 20px;font-weight: bold;text-align: left\">Conclusion<\/h2>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">To recap, <span style=\"font-family: monospace\">exportgraphics<\/span> and <span style=\"font-family: monospace\">copygraphics<\/span> now support specifying output size, as well as support some additional functionality that allows you control over maintaining the aspect ratio and the padding. Previously, you may have used <span style=\"font-family: monospace\">print<\/span> to specify output size by using the less intuitive method of changing properties on the figure before printing, which also did not allow as much control as the new name-value pairs.<\/div>\r\n<div style=\"margin: 2px 10px 9px 4px;padding: 0px;line-height: 21px;min-height: 0px;font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif;font-style: normal;font-size: 14px;font-weight: 400;text-align: left\">Please leave a comment and let me know what additional exporting features you're interested in having us work on in the future!<\/div>\r\n&nbsp;\r\n\r\n<\/div>\r\n<script type=\"text\/javascript\">\r\n{ let css = '';\r\nlet head = document.head || document.getElementsByTagName('head')[0];\r\nlet style = document.createElement('style');\r\nhead.appendChild(style);\r\nstyle.type = 'text\/css';\r\nif (style.styleSheet) {\r\n    style.styleSheet.cssText = css;\r\n} else {\r\n    style.appendChild(document.createTextNode(css));\r\n}\r\n\r\n\r\n}<\/script><a href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/files\/2025\/12\/exportgraphics_size_layout.mlx-12-05-25_0.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>&nbsp;\r\n\r\n\r\n\r\n\r\nGuest Writer: Leia Rich\r\nLeia is a software engineer on the MATLAB Charting Team. She first joined MathWorks as part of the Engineering Development Group (EDG) in 2022, and later... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2025\/12\/08\/advanced-control-of-size-and-layout-of-exported-graphics\/\">read more >><\/a><\/p>","protected":false},"author":198,"featured_media":3563,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,11,20,38],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/3543"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/users\/198"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/comments?post=3543"}],"version-history":[{"count":10,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/3543\/revisions"}],"predecessor-version":[{"id":3634,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/posts\/3543\/revisions\/3634"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/media\/3563"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/media?parent=3543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/categories?post=3543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/graphics-and-apps\/wp-json\/wp\/v2\/tags?post=3543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}