Search code examples
matlabmatlab-figurecontour

How to make dotted/dashed lines look realistic in contour plots - Matlab


The dotted/dashed lines in Matlab graphs look somewhat fine in the figure window, but when printed, they lose resolution and look really bad. See Figure below. How can I make the dotted/dashed lines look exactly like on screen?

Example Contour Plot with annotations on contours


Solution

  • I would use the method suggested by Loren from her excellent post on making pretty graphs. It uses a function that she wrote which goes into the output eps file, and tweaks the definition of the dotted lines. fixPSlinestyle is found on the FEX.

    figure('renderer','painters')
    hold on
    plot([1 2 4],[2 3 7],'r-','linewidth',13)
    plot([1 2 4],[2.5 3.5 7.5],'b:','linewidth',13)
    
    print(gcf,'-depsc2','withoutedit.eps')
    fixPSlinestyle('withoutedit.eps','withedit.eps')
    

    The first figure (withoutedit.eps) is shown on left, and after the eps linestyle has been tweaked is shown at right (withedit.eps):

    enter image description here

    I like this solution because you're not handing complete control to a function - you control the exporting of the figure (through the print command), but you use a function to tweak the final eps file.