Output high-resolution figure from Matlab with full picture - matlab

I want to output a high-resolution figure from Matlab.
I tried to "save as pic.eps". But when I insert this picture in latex, it seems that the picture is not "real eps" in the sense that I can tell that the resolution is not enough.
I also tried to "save as pic.pdf". The resolution meets my demand, but the pic is cropped, as it is too large.
Then I used
print -depsc -tiff -r300 -painters pic.eps
This gives me the high-resolution full picture, but some of the dashed lines in the original picture disappeared. I have tried many other cases and still couldn't find the right way to solve my problem. Any suggestions are highly appreciated

I'd try to save eps in vector format, or use a vector only format such as .svg.
For example,
print -depsc2 -painters test.eps
These are the vector graphics supported formats according to the current documentation:
Option Vector Graphics Format File Extension
'-dpdf' Full page Portable Document Format (PDF) color .pdf
'-deps' Encapsulated PostScript (EPS) Level 3 black and white .eps
'-depsc' Encapsulated PostScript (EPS) Level 3 color .eps
'-deps2' Encapsulated PostScript (EPS) Level 2 black and white .eps
'-depsc2' Encapsulated PostScript (EPS) Level 2 color .eps
'-dmeta' Enhanced Metafile (Windows® only) .emf
'-dsvg' SVG (Scalable Vector Graphics) .svg
'-dps' Full-page PostScript (PS) Level 3 black and white .ps
'-dpsc' Full-page PostScript (PS) Level 3 color .ps
'-dps2' Full-page PostScript (PS) Level 2 black and white .ps
'-dpsc2' Full-page PostScript (PS) Level 2 color .ps
you'll also have to use the '-painters' renderer when saving vector graphics files. If you save to a vector graphics file and if the figure RendererMode property is set to 'auto', then print automatically attempts to use the Painters renderer. If you want to ensure that your output format is a true vector graphics file, then specify the Painters renderer. For example:
print('-painters','-deps','myVectorFile')

this command in question may come from the following link
After removing -tiff, my issue of missing one line was fixed (even though I don't understand what is '-tiff' for)

Related

Cant export matlab figure using custom font

I'm trying to export my plot with Tahoma font :
However I always end up with the following figure :
Which is not the font I chose !! can someone tell me why is this happening ?
Also, the legend's font do not change either.
For export figures in MATLAB, I highly recommend you to try export_fig. WYSIWYG!
This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties:
Figure/axes reproduced as it appears on screen
Cropped borders (optional)
Embedded fonts (pdf only)
Improved line and grid line styles
Anti-aliased graphics (bitmap formats)
Render images at native resolution (optional for bitmap formats)
Transparent background supported (pdf, eps, png)
Semi-transparent patch objects supported (png only)
RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff)
Variable image compression, including lossless (pdf, eps, jpg)
Optionally append to file (pdf, tiff)
Vector formats: pdf, eps
Bitmap formats: png, tiff, jpg, bmp, export to workspace
This function is especially suited to exporting figures for use in publications and presentations, because of the high quality and portability of media produced.
I think you cannot embed fonts to MATLAB figures normally, you can just use Type1 fonts.
Check this MATLAB function, by Oliver Woodford, maybe it can help: [Link]

How to improve the quality (smoothness) of lines in contourplots Matlab's

How the line smoothness in a contour plot can be improved for publications? For instance, the dotted lines look really bad, the continuous lines look as if their thickness varies. See below
Here's part of the code:
Vals = [0:5:200]; contourf(X,Y,W,Vals,'EdgeColor','k','LineWidth',1.2,'LineStyle',':');axis square;grid;hold on
Vals = [10:10:200]; contour(X,Y,W,Vals,'EdgeColor','k','LineWidth',1.2);
Vals = [20 : 20 : 200]; [C,h] = contour(X,Y,W,Vals,'Color','k','LineWidth',1.8);
clabel(C,h,'FontName','Palatino Linotype','FontAngle','italic','Fontsize',9,'Color','w')
print -djpeg -r300 filename
Thanks!
Saved as png doesn't help much... check the lines :/ See below:
Check the dotted lines now...
Here's saving as eps (-r1200)... it looks better
Exporting as vector graphics will definitely improve the image over what you see on your screen; I use LaTeX for publications and you can either export to eps for postscript output, and use epstopdf for PDF output, and embed these directly in your document; that would be the best solution.
Additionally, there are also a bunch of general utilities for making your plots look better for camera-ready publications, the most notable that comes to mind is exportfig, which has a load of features to help even with pixel graphics. These go above and beyond just generating smoother-looking images.
http://www.mathworks.us/matlabcentral/fileexchange/23629-exportfig
(copied from that page):
This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties:
Figure/axes reproduced as it appears on screen
Cropped borders (optional)
Embedded fonts (pdf only)
Improved line and grid line styles
Anti-aliased graphics (bitmap formats)
Render images at native resolution (optional for bitmap formats)
Transparent background supported (pdf, eps, png)
Semi-transparent patch objects supported (png only)
RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff)
Variable image compression, including lossless (pdf, eps, jpg)
Optionally append to file (pdf, tiff)
Vector formats: pdf, eps
Bitmap formats: png, tiff, jpg, bmp, export to workspace
This function is especially suited to exporting figures for use in publications and presentations, because of the high quality and portability of media produced.
Update: I see your example code now. Did you try changing -r300 to some really high value? More pixels per inch should make everything look smoother. For publication, crank it up really high, like -r1200.
Original:
One thing you can try is exporting the plot in some format that supports vector graphics. Matlab supports both PDF and EMF, so try one of those. Export using the saveas command or from the figure's "File -> Save as" menu item. After that, open or import the image file in some other application and hopefully it will look better.
Please add a new screenshot if you get a nicer image!

Matlab: How to save plots of patches / fill() automatically in the code?

quick question: I'm creating "random" polygons using either the patch() or the fill() function in Matlab. This works quite good and it is plotted correctly.
However, I need to at least save a few hundres polygons as images to my hard drive for working with them later - so I'm looking for a way to directly save the image in my function rather than saving each polygon myself using the file-menu.
Is there any way to do this?
Thanks in advance!
You can indeed use the print function, but I would not use the jpeg device. JPEG is never the right format for plots (you will get a lot of artifacts near all your lines).
If you need a bitmap image, try the png or tiff device. If you don't need a bitmap, use the appropriate vector image format: fig is the native MATLAB format (which allows you to edit the plot afterwards), so this is the best one if you stick with MATLAB for all your operations. For exporting to other software, I would recommend pdf (works almost anywhere), epsc (EPS with color, great for LaTeX or inkscape), wmf/emf (Windows Metafile, so Windows only, but great for including the images in MS Office). Or you could of course use any of the other formats mentioned in the print documentation.
Sometimes it's a pain in the neck to get the format of your image all right (especially with PDF output). Just take a look at the different properties of your figure and more specifically the PaperSize, PaperUnits and PaperPosition.
The easiest way, and I guess the best solution, is to save as a .fig file. You can do this by using saveas:
h = figure;
% your plot commands here
saveas(h,'mFile.fig');
Afterwards, you can reload the image with the openfig function:
openfig('mFile.fig');
Have to add this answer. This function is helping a lot.
This function saves a figure or single axes to one or more vector and/or bitmap file formats, and/or outputs a rasterized version to the workspace, with the following properties:
   - Figure/axes reproduced as it appears on screen
   - Cropped/padded borders (optional)
   - Embedded fonts (pdf only)
   - Improved line and grid line styles
   - Anti-aliased graphics (bitmap formats)
   - Render images at native resolution (optional for bitmap formats)
   - Transparent background supported (pdf, eps, png)
   - Semi-transparent patch objects supported (png only)
   - RGB, CMYK or grayscale output (CMYK only with pdf, eps, tiff)
   - Variable image compression, including lossless (pdf, eps, jpg)
   - Optionally append to file (pdf, tiff)
   - Vector formats: pdf, eps
   - Bitmap formats: png, tiff, jpg, bmp, export to workspace

Getting rid of interpolation/aliasing in EPS export of matlab?

I have a 2D color-map plot created with imagesc and want to export it as a .eps file using
print -depsc.
The problem is that the "original" image data is from a rather small matrix (131 x 131). When I view the image in the matlab figure window, I can see all the individual pixels if I zoom a bit closer.
When I export to eps, however, there seems to be some interpolation or anti-aliasing going on, in that neighboring pixels get blurred/blended into each other. I don't get the problem if I export a high-resolution tiff, but that format is not an option (as demanded by a publisher).
How can I obtain an eps that preserves the pixely structure of my image without applying interpolation or anti-aliasing?
The blurring actually depends on the rendering software your viewer application or printer uses. To get good results all the time, make each pixel in your image an 8x8 block of pixels of the same color. The blurring then only affects the pixels at the edge of each block. 8x8 blocks are best as they compress without nasty artifacts using DCT compression (sometimes used in eps files).
Old question, but highly ranked in Google, so here is my answer:
Open the .eps-file with a text editor, search for "Interpolate" and change the following "true" to "false". Repeat that step for all Interpolate-statements.
It might also depend on the viewer you're using, but probably just because some viewers ignore the "Interpolate"s...
Had the same problem using plot2svg in Matlab and exporting from Inkscape to eps.

Saving MATLAB graphs in a specific resolution

How do I change the resolution of my MATLAB graphs? The default seems to be 96x96 PPI.
You can save using the print command; here's how:
h1=figure;
your plotting commands here
print(h1,'-djpeg','-r150','filename')
The -r150 argument sets the resolution to 150 DPI. you can set it higher or lower depending on your need. This is assuming you're saving as a JPEG. If not, there are other options such as -dpng for PNG, -dbmp for 24-bit bitmap, etc. more can be found in the help section for print.
That said, if your plot consists only of lines, I would recommend using -depsc which saves it as an EPS file, which is scalable and lossless. You also won't have to define a resolution, so you can simply do
print(h1,'-depsc','filename')
You can convert this EPS file to PDF and retain the same resolution, yet have portability between applications and platforms. I wouldn't recommend saving to PDF directly as MATLAB puts additional white spaces around the plot, wheras the EPS bounding box is tight, and looks neat.
Changing a Figure's Settings: Setting the resolution