{"id":118,"date":"2007-12-11T09:00:44","date_gmt":"2007-12-11T14:00:44","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/2007\/12\/11\/making-pretty-graphs\/"},"modified":"2025-05-15T01:48:18","modified_gmt":"2025-05-15T05:48:18","slug":"making-pretty-graphs","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2007\/12\/11\/making-pretty-graphs\/","title":{"rendered":"Making Pretty Graphs"},"content":{"rendered":"<div class=\"content\">\n<table style=\"background-color: #e2f0ff; border: 1px solid black; font-size: 14pt\">\n<tbody>\n<tr>\n<td style=\"vertical-align: middle;padding: 3px\"><strong>Update (2025): <\/strong>Looking for the latest techniques for making pretty graphics? Check out our <a href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/2025\/05\/14\/making-even-prettier-graphs\/\">2025 revisit of this article<\/a> in the <a href=\"https:\/\/blogs.mathworks.com\/graphics-and-apps\/\" rel=\"noopener\" target=\"_blank\">Graphics and App Building blog<\/a>, featuring modern approaches and updated MATLAB features for creating publication-quality graphics.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n<p>Today I\u2019d like to introduce a guest blogger, Jiro Doke (email: <a href=\"mailto:Jiro.Doke@mathworks.com\">Jiro.Doke@mathworks.com<\/a>), who is an applications engineer here at The MathWorks. He used MATLAB in his life prior to The MathWorks, and one of his interests is data visualization.<br \/>\n&nbsp;<\/p>\n<h3>Contents<\/h3>\n<div>\n<ul>\n<li><a href=\"#2\">Load Data<\/a><\/li>\n<li><a href=\"#3\">Create Basic Plot<\/a><\/li>\n<li><a href=\"#4\">Adjust Line Properties (Functional)<\/a><\/li>\n<li><a href=\"#5\">Adjust Line Properties (Esthetics)<\/a><\/li>\n<li><a href=\"#6\">Add Legend and Labels<\/a><\/li>\n<li><a href=\"#7\">Adjust Font and Axes Properties<\/a><\/li>\n<li><a href=\"#8\">Export to EPS<\/a><\/li>\n<li><a href=\"#10\">Postprocess<\/a><\/li>\n<li><a href=\"#13\">Your Examples<\/a><\/li>\n<\/ul>\n<\/div>\n<p>In my graduate work, I used MATLAB extensively for doing analysis and visualization. Often times, the plots that I created<br \/>\nwere used for my publications. It was then when I started to explore the flexibility of Handle Graphics to customize MATLAB<br \/>\nplots in order to create publication-quality graphics. Ultimately, I was able to use MATLAB almost exclusively for my plots.<\/p>\n<p>Let me walk you through the step-by-step process of how I did it. I'm using some fabricated data, but the plot is very similar<br \/>\nto the ones I generated for my research.<\/p>\n<h3>Load Data<a name=\"2\"><\/a><\/h3>\n<p>First you might download the <a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/data.mat\">data<\/a>.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">load <span style=\"color: #a020f0;\">data<\/span><\/pre>\n<h3>Create Basic Plot<a name=\"3\"><\/a><\/h3>\n<p>First, I plot my data to create the crude visualization<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">figure(<span style=\"color: #a020f0;\">'Units'<\/span>, <span style=\"color: #a020f0;\">'pixels'<\/span>, <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'Position'<\/span>, [100 100 500 375]);\r\nhold <span style=\"color: #a020f0;\">on<\/span>;\r\n\r\nhFit   = line(xfit  , yfit   );\r\nhE     = errorbar(xdata_m, ydata_m, ydata_s);\r\nhData  = line(xVdata, yVdata );\r\nhModel = line(xmodel, ymodel );\r\nhCI(1) = line(xmodel, ymodelL);\r\nhCI(2) = line(xmodel, ymodelU);<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/pubQualityGraphics_01.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Adjust Line Properties (Functional)<a name=\"4\"><\/a><\/h3>\n<p>Next, I do my first-round modification of my plots. At this point, I'm not worried about the esthetics yet.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">set(hFit                          , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Color'<\/span>           , [0 0 .5]    );\r\nset(hE                            , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineStyle'<\/span>       , <span style=\"color: #a020f0;\">'none'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Marker'<\/span>          , <span style=\"color: #a020f0;\">'.'<\/span>         , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Color'<\/span>           , [.3 .3 .3]  );\r\nset(hData                         , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineStyle'<\/span>       , <span style=\"color: #a020f0;\">'none'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Marker'<\/span>          , <span style=\"color: #a020f0;\">'.'<\/span>         );\r\nset(hModel                        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineStyle'<\/span>       , <span style=\"color: #a020f0;\">'--'<\/span>        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Color'<\/span>           , <span style=\"color: #a020f0;\">'r'<\/span>         );\r\nset(hCI(1)                        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineStyle'<\/span>       , <span style=\"color: #a020f0;\">'-.'<\/span>        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Color'<\/span>           , [0 .5 0]    );\r\nset(hCI(2)                        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineStyle'<\/span>       , <span style=\"color: #a020f0;\">'-.'<\/span>        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Color'<\/span>           , [0 .5 0]    );<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/pubQualityGraphics_02.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Adjust Line Properties (Esthetics)<a name=\"5\"><\/a><\/h3>\n<p>To make it more publication-quality, I make the following changes to the line properties, including the errorbar widths. In<br \/>\nmy opinion, using thicker lines and larger markers greatly improves the \"look\" of my graphics. It's quite subjective, but<br \/>\nI select them based on how much data is on the graph. I select the appropriate \"crowdedness\" (balance of dark and white space):<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">set(hFit                          , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineWidth'<\/span>       , 2           );\r\nset(hE                            , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineWidth'<\/span>       , 1           , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Marker'<\/span>          , <span style=\"color: #a020f0;\">'o'<\/span>         , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'MarkerSize'<\/span>      , 6           , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'MarkerEdgeColor'<\/span> , [.2 .2 .2]  , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'MarkerFaceColor'<\/span> , [.7 .7 .7]  );\r\nset(hData                         , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Marker'<\/span>          , <span style=\"color: #a020f0;\">'o'<\/span>         , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'MarkerSize'<\/span>      , 5           , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'MarkerEdgeColor'<\/span> , <span style=\"color: #a020f0;\">'none'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'MarkerFaceColor'<\/span> , [.75 .75 1] );\r\nset(hModel                        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineWidth'<\/span>       , 1.5         );\r\nset(hCI(1)                        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineWidth'<\/span>       , 1.5         );\r\nset(hCI(2)                        , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineWidth'<\/span>       , 1.5         );\r\n\r\n<span style=\"color: #228b22;\">% adjust error bar width<\/span>\r\nhE_c                   = <span style=\"color: #0000ff;\">...<\/span>\r\n    get(hE     , <span style=\"color: #a020f0;\">'Children'<\/span>    );\r\nerrorbarXData          = <span style=\"color: #0000ff;\">...<\/span>\r\n    get(hE_c(2), <span style=\"color: #a020f0;\">'XData'<\/span>       );\r\nerrorbarXData(4:9:end) = <span style=\"color: #0000ff;\">...<\/span>\r\n    errorbarXData(1:9:end) - 0.2;\r\nerrorbarXData(7:9:end) = <span style=\"color: #0000ff;\">...<\/span><span style=\"color: #228b22;\">.<\/span>\r\n    errorbarXData(1:9:end) - 0.2;\r\nerrorbarXData(5:9:end) = <span style=\"color: #0000ff;\">...<\/span>\r\n    errorbarXData(1:9:end) + 0.2;\r\nerrorbarXData(8:9:end) = <span style=\"color: #0000ff;\">...<\/span>\r\n    errorbarXData(1:9:end) + 0.2;\r\nset(hE_c(2), <span style=\"color: #a020f0;\">'XData'<\/span>, errorbarXData);<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/pubQualityGraphics_03.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Add Legend and Labels<a name=\"6\"><\/a><\/h3>\n<p>No plot is complete unless it is well annotated.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">hTitle  = title (<span style=\"color: #a020f0;\">'My Publication-Quality Graphics'<\/span>);\r\nhXLabel = xlabel(<span style=\"color: #a020f0;\">'Length (m)'<\/span>                     );\r\nhYLabel = ylabel(<span style=\"color: #a020f0;\">'Mass (kg)'<\/span>                      );\r\n\r\nhText   = text(10, 800, <span style=\"color: #0000ff;\">...<\/span>\r\n  sprintf(<span style=\"color: #a020f0;\">'\\\\it{C = %0.1g \\\\pm %0.1g (CI)}'<\/span>, <span style=\"color: #0000ff;\">...<\/span>\r\n  c, cint(2)-c));\r\n\r\nhLegend = legend( <span style=\"color: #0000ff;\">...<\/span>\r\n  [hE, hFit, hData, hModel, hCI(1)], <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Data (\\mu \\pm \\sigma)'<\/span> , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Fit (\\it{C x^3})'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Validation Data'<\/span>       , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Model (\\it{C x^3})'<\/span>    , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'95% CI'<\/span>                , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'location'<\/span>, <span style=\"color: #a020f0;\">'NorthWest'<\/span> );<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/pubQualityGraphics_04.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Adjust Font and Axes Properties<a name=\"7\"><\/a><\/h3>\n<p>Since many publications accept EPS formats, I select fonts that are supported by PostScript and Ghostscript. Anything that's<br \/>\nnot supported will be replaced by Courier. I also define tick locations, especially when the default is too crowded.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">set( gca                       , <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'FontName'<\/span>   , <span style=\"color: #a020f0;\">'Helvetica'<\/span> );\r\nset([hTitle, hXLabel, hYLabel, hText], <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'FontName'<\/span>   , <span style=\"color: #a020f0;\">'AvantGarde'<\/span>);\r\nset([hLegend, gca]             , <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'FontSize'<\/span>   , 8           );\r\nset([hXLabel, hYLabel, hText]  , <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'FontSize'<\/span>   , 10          );\r\nset( hTitle                    , <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'FontSize'<\/span>   , 12          , <span style=\"color: #0000ff;\">...<\/span>\r\n    <span style=\"color: #a020f0;\">'FontWeight'<\/span> , <span style=\"color: #a020f0;\">'bold'<\/span>      );\r\n\r\nset(gca, <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'Box'<\/span>         , <span style=\"color: #a020f0;\">'off'<\/span>     , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'TickDir'<\/span>     , <span style=\"color: #a020f0;\">'out'<\/span>     , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'TickLength'<\/span>  , [.02 .02] , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'XMinorTick'<\/span>  , <span style=\"color: #a020f0;\">'on'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'YMinorTick'<\/span>  , <span style=\"color: #a020f0;\">'on'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'YGrid'<\/span>       , <span style=\"color: #a020f0;\">'on'<\/span>      , <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'XColor'<\/span>      , [.3 .3 .3], <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'YColor'<\/span>      , [.3 .3 .3], <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'YTick'<\/span>       , 0:500:2500, <span style=\"color: #0000ff;\">...<\/span>\r\n  <span style=\"color: #a020f0;\">'LineWidth'<\/span>   , 1         );<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/pubQualityGraphics_05.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Export to EPS<a name=\"8\"><\/a><\/h3>\n<p>I set <tt>PaperPositionMode<\/tt> to auto so that the exported figure looks like it does on the screen.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">set(gcf, <span style=\"color: #a020f0;\">'PaperPositionMode'<\/span>, <span style=\"color: #a020f0;\">'auto'<\/span>);\r\nprint <span style=\"color: #a020f0;\">-depsc2<\/span> <span style=\"color: #a020f0;\">finalPlot1.eps<\/span>\r\nclose;<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/finalPlot1.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<h3>Postprocess<a name=\"10\"><\/a><\/h3>\n<p>This looks great! One thing that I may want to change is the way the dotted and dashed lines look. Notice that the dots are<br \/>\ntoo small. So, I wrote a simple function that goes into the EPS file and modifies the line definitions. I have posted the<br \/>\nfunction, <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=17928&amp;objectType=file (link no longer works)\"><tt>fixPSlinestyle<\/tt><\/a>, on the File Exchange.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">fixPSlinestyle(<span style=\"color: #a020f0;\">'finalPlot1.eps'<\/span>, <span style=\"color: #a020f0;\">'finalPlot2.eps'<\/span>);<\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/118\/finalPlot2.png\" hspace=\"5\" vspace=\"5\" \/><\/p>\n<p>And there you go. I have automated the process of creating publication-quality graphics. <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/graphics-objects.html\">Handle Graphics<\/a> give you advanced control of how graphics look. In case you didn't know, MATLAB allows you to quickly take a MATLAB script<br \/>\nand publish a formated report (HTML, Word, LaTeX, XML, PPT), where the figures are automatically converted to various graphics format,<br \/>\nincluding EPS. This document was created using <tt>publish<\/tt>.<\/p>\n<h3>Your Examples<a name=\"13\"><\/a><\/h3>\n<p>Tell us <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=118#respond\">here<\/a> about some of the cool things you do with Handle Graphics to make your figures look prettier.<\/p>\n<p><script>\/\/ <![CDATA[\nfunction grabCode_648e841d930944218747e3e633422d0f() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='648e841d930944218747e3e633422d0f ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 648e841d930944218747e3e633422d0f';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Loren Shure';\n        copyright = 'Copyright 2007 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n\n\n\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\n\n\n\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }\n\/\/ ]]><\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\"><a><span style=\"font-size: x-small; font-style: italic;\">Get<br \/>\nthe MATLAB code<br \/>\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>Published with MATLAB\u00ae 7.5<\/p>\n<\/div>\n<p><!--\n648e841d930944218747e3e633422d0f ##### SOURCE BEGIN #####\n%% Making Pretty Graphs\n% Today I\u00e2\u20ac&#x2122;d like to introduce a guest blogger,\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadAuthor.do?objectType=author&objectId=1094142 % Jiro Doke> (email: Jiro.Doke@mathworks.com), who is an applications\n% engineer here at The MathWorks. He used MATLAB in his life prior to The\n% MathWorks, and one of his interests is data visualization.\n\n%%\n% In my graduate work, I used MATLAB extensively for doing analysis and\n% visualization. Often times, the plots that I created were used for my\n% publications. It was then when I started to explore the flexibility of\n% Handle Graphics to customize MATLAB plots in order to create\n% publication-quality graphics. Ultimately, I was able to use MATLAB almost\n% exclusively for my plots.\n%\n% Let me walk you through the step-by-step process of how I did it. I'm\n% using some fabricated data, but the plot is very similar to the ones I\n% generated for my research.\n\n%% Load Data\n\nload data\n\n%% Create Basic Plot\n% First, I plot my data to create the crude visualization\n\nfigure('Units', 'pixels', ...\n'Position', [100 100 500 375]);\nhold on;\n\nhFit   = line(xfit  , yfit   );\nhE     = errorbar(xdata_m, ydata_m, ydata_s);\nhData  = line(xVdata, yVdata );\nhModel = line(xmodel, ymodel );\nhCI(1) = line(xmodel, ymodelL);\nhCI(2) = line(xmodel, ymodelU);\n\n%% Adjust Line Properties (Functional)\n% Next, I do my first-round modification of my plots. At this point, I'm\n% not worried about the esthetics yet.\n\nset(hFit                          , ...\n'Color'           , [0 0 .5]    );\nset(hE                            , ...\n'LineStyle'       , 'none'      , ...\n'Marker'          , '.'         , ...\n'Color'           , [.3 .3 .3]  );\nset(hData                         , ...\n'LineStyle'       , 'none'      , ...\n'Marker'          , '.'         );\nset(hModel                        , ...\n'LineStyle'       , 'REPLACE_WITH_DASH_DASH'        , ...\n'Color'           , 'r'         );\nset(hCI(1)                        , ...\n'LineStyle'       , '-.'        , ...\n'Color'           , [0 .5 0]    );\nset(hCI(2)                        , ...\n'LineStyle'       , '-.'        , ...\n'Color'           , [0 .5 0]    );\n\n%% Adjust Line Properties (Esthetics)\n% To make it more publication-quality, I make the following changes to the\n% line properties, including the errorbar widths. In my opinion, using\n% thicker lines and larger markers greatly improves the \"look\" of my\n% graphics. It's quite subjective, but I select them based on how much data\n% is on the graph. I select the appropriate \"crowdedness\" (balance of dark\n% and white space):\n\nset(hFit                          , ...\n'LineWidth'       , 2           );\nset(hE                            , ...\n'LineWidth'       , 1           , ...\n'Marker'          , 'o'         , ...\n'MarkerSize'      , 6           , ...\n'MarkerEdgeColor' , [.2 .2 .2]  , ...\n'MarkerFaceColor' , [.7 .7 .7]  );\nset(hData                         , ...\n'Marker'          , 'o'         , ...\n'MarkerSize'      , 5           , ...\n'MarkerEdgeColor' , 'none'      , ...\n'MarkerFaceColor' , [.75 .75 1] );\nset(hModel                        , ...\n'LineWidth'       , 1.5         );\nset(hCI(1)                        , ...\n'LineWidth'       , 1.5         );\nset(hCI(2)                        , ...\n'LineWidth'       , 1.5         );\n\n% adjust error bar width\nhE_c                   = ...\nget(hE     , 'Children'    );\nerrorbarXData          = ...\nget(hE_c(2), 'XData'       );\nerrorbarXData(4:9:end) = ...\nerrorbarXData(1:9:end) - 0.2;\nerrorbarXData(7:9:end) = ....\nerrorbarXData(1:9:end) - 0.2;\nerrorbarXData(5:9:end) = ...\nerrorbarXData(1:9:end) + 0.2;\nerrorbarXData(8:9:end) = ...\nerrorbarXData(1:9:end) + 0.2;\nset(hE_c(2), 'XData', errorbarXData);\n\n%% Add Legend and Labels\n% No plot is complete unless it is well annotated.\n\nhTitle  = title ('My Publication-Quality Graphics');\nhXLabel = xlabel('Length (m)'                     );\nhYLabel = ylabel('Mass (kg)'                      );\n\nhText   = text(10, 800, ...\nsprintf('\\\\it{C = %0.1g \\\\pm %0.1g (CI)}', ...\nc, cint(2)-c));\n\nhLegend = legend( ...\n[hE, hFit, hData, hModel, hCI(1)], ...\n'Data (\\mu \\pm \\sigma)' , ...\n'Fit (\\it{C x^3})'      , ...\n'Validation Data'       , ...\n'Model (\\it{C x^3})'    , ...\n'95% CI'                , ...\n'location', 'NorthWest' );\n\n%% Adjust Font and Axes Properties\n% Since many publications accept EPS formats, I select fonts that are\n% supported by PostScript and Ghostscript. Anything that's not supported\n% will be replaced by Courier. I also define tick locations, especially\n% when the default is too crowded.\n\nset( gca                       , ...\n'FontName'   , 'Helvetica' );\nset([hTitle, hXLabel, hYLabel, hText], ...\n'FontName'   , 'AvantGarde');\nset([hLegend, gca]             , ...\n'FontSize'   , 8           );\nset([hXLabel, hYLabel, hText]  , ...\n'FontSize'   , 10          );\nset( hTitle                    , ...\n'FontSize'   , 12          , ...\n'FontWeight' , 'bold'      );\n\nset(gca, ...\n'Box'         , 'off'     , ...\n'TickDir'     , 'out'     , ...\n'TickLength'  , [.02 .02] , ...\n'XMinorTick'  , 'on'      , ...\n'YMinorTick'  , 'on'      , ...\n'YGrid'       , 'on'      , ...\n'XColor'      , [.3 .3 .3], ...\n'YColor'      , [.3 .3 .3], ...\n'YTick'       , 0:500:2500, ...\n'LineWidth'   , 1         );\n\n%% Export to EPS\n% I set |PaperPositionMode| to auto so that the exported figure looks like\n% it does on the screen.\n\nset(gcf, 'PaperPositionMode', 'auto');\nprint -depsc2 finalPlot1.eps\nclose;\n\n%%\n% <<finalPlot1.png>>\n\n%% Postprocess\n% This looks great! One thing that I may want to change is the way the\n% dotted and dashed lines look. Notice that the dots are too small. So, I\n% wrote a simple function that goes into the EPS file and modifies the line\n% definitions. I have posted the function,\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=17928&objectType=file % |fixPSlinestyle|>, on the File Exchange.\n\nfixPSlinestyle('finalPlot1.eps', 'finalPlot2.eps');\n\n%%\n% <<finalPlot2.png>>\n\n%%\n% And there you go. I have automated the process of creating\n% publication-quality graphics.\n% <https:\/\/www.mathworks.com\/help\/matlab\/graphics-objects.html % Handle Graphics> give you advanced control of how graphics look. In case\n% you didn't know, MATLAB allows you to quickly take a MATLAB script and\n% <https:\/\/www.mathworks.com\/access\/helpdesk\/help\/techdoc\/matlab_env\/f6-22451.html % |publish|> a formated report (HTML, Word, LaTeX, XML, PPT), where the\n% figures are automatically converted to various graphics format, including\n% EPS. This document was created using |publish|.\n\n%% Your Examples\n% Tell us <https:\/\/blogs.mathworks.com\/loren\/?p=118#respond here> about some\n% of the cool things you do with Handle Graphics to make your figures look\n% prettier.\n##### SOURCE END ##### 648e841d930944218747e3e633422d0f\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update (2025): Looking for the latest techniques for making pretty graphics? Check out our 2025 revisit of this article in the Graphics and App Building blog, featuring modern approaches and... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2007\/12\/11\/making-pretty-graphs\/\">read more >><\/a><\/p>\n","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,21,15],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/118"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"predecessor-version":[{"id":5270,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/118\/revisions\/5270"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}