You are currently browsing the Carl's notes weblog archives for August, 2012.

Matlab figures: dashed lines, orientation, EPS export and conversion to PNG

More trouble getting decent figures out of Matlab. Solved a few of my problems.

Dashed and dotted lines look weird when exported to EPS. There are several scripts available on the Mathworks FileExchange. One that I’ve just tried by Oliver Woodford, and an earlier one mentioned by Loren Shure in her article on making pretty figures. You could edit the EPS files manually to change the parameters of the lines but these scripts will do it for you.

The PNG export appears to suffer from the same problem regarding dashed or dotted lines but without the option to modify the final file (because it’s not a vector format). Since the EPS files look good, I might as well convert them to PNG. Using ImageMagick for batch conversion under Linux wouldn’t be a problem but I’m currently using Windows. But it’s just as easy and with the mogrify command you won’t even need to write a loop. Open a command terminal, change to the directory where your files are, and run mogrify -format png -resize 2048 -density 600 *.eps. The resize option determines the dimensions of the PNG, and the density option ensures that it’s not blurry. The PNG files will be named the same as the EPS files but with their own extension.

One of my figures needed to be rotated 90 degrees to look better on the screen and make exporting it easier (although it’s perhaps not absolutely necessary for it to be entirely visible on the screen). I didn’t want the trouble of changing all my coordinates. Running camroll(90) has pretty much the desired effect but messes up the axes’ labels. view(90,90) worked better for me. Thanks andyras and Rachel on StackOverflow. You may need to set limits and labels after performing the rotation.