Giter Site home page Giter Site logo

export_fig's Introduction

export_fig

A toolbox for exporting figures from MATLAB to standard image and document formats nicely.

Overview

Exporting a figure from MATLAB the way you want it (hopefully the way it looks on screen), can be a real headache for the unitiated, thanks to all the settings that are required, and also due to some eccentricities (a.k.a. features and bugs) of functions such as print. The first goal of export_fig is to make transferring a plot from screen to document, just the way you expect (again, assuming that's as it appears on screen), a doddle.

The second goal is to make the output media suitable for publication, allowing you to publish your results in the full glory that you originally intended. This includes embedding fonts, setting image compression levels (including lossless), anti-aliasing, cropping, setting the colourspace, alpha-blending and getting the right resolution.

Perhaps the best way to demonstrate what export_fig can do is with some examples.

Note: export_fig currently supports only figures created with the figure function, or GUIDE. Figures created using uifigure or AppDesigner are only partially supported. See issues #287, #261 for details.

Examples

Visual accuracy - MATLAB's exporting functions, namely saveas and print, change many visual properties of a figure, such as size, axes limits and ticks, and background colour, in unexpected and unintended ways. Export_fig aims to faithfully reproduce the figure as it appears on screen. For example:

plot(cos(linspace(0, 7, 1000)));
set(gcf, 'Position', [100 100 150 150]);
saveas(gcf, 'test.png');
export_fig test2.png

generates the following:

Figure: test.png: test2.png:

Note that the size and background colour of test2.png (the output of export_fig) are the same as those of the on screen figure, in contrast to test.png. Of course, if you want the figure background to be white (or any other colour) in the exported file then you can set this prior to exporting using:

set(gcf, 'Color', 'w');

Notice also that export_fig crops and anti-aliases (smooths, for bitmaps only) the output by default. However, these options can be disabled; see the Tips section below for details.

Resolution - by default, export_fig exports bitmaps at screen resolution. However, you may wish to save them at a different resolution. You can do this using either of two options: -m<val>, where is a positive real number, magnifies the figure by the factor for export, e.g. -m2 produces an image double the size (in pixels) of the on screen figure; -r<val>, again where is a positive real number, specifies the output bitmap to have pixels per inch, the dimensions of the figure (in inches) being those of the on screen figure. For example, using:

export_fig test.png -m2.5

on the figure from the example above generates:

Sometimes you might have a figure with an image in. For example:

imshow(imread('cameraman.tif'))
hold on
plot(0:255, sin(linspace(0, 10, 256))*127+128);
set(gcf, 'Position', [100 100 150 150]);

generates this figure:

Here the image is displayed in the figure at resolution lower than its native resolution. However, you might want to export the figure at a resolution such that the image is output at its native (i.e. original) size (in pixels). Ordinarily this would require some non-trivial computation to work out what that resolution should be, but export_fig has an option to do this for you. Using:

export_fig test.png -native

produces:

with the image being the size (in pixels) of the original image. Note that if you want an image to be a particular size, in pixels, in the output (other than its original size) then you can resize it to this size and use the -native option to achieve this.

All resolution options (-m<val>, -q<val> and -native) correctly set the resolution information in PNG and TIFF files, as if the image were the dimensions of the on screen figure.

Shrinking dots & dashes - when exporting figures with dashed or dotted lines using either the ZBuffer or OpenGL (default for bitmaps) renderers, the dots and dashes can appear much shorter, even non-existent, in the output file, especially if the lines are thick and/or the resolution is high. For example:

plot(sin(linspace(0, 10, 1000)), 'b:', 'LineWidth', 4);
hold on
plot(cos(linspace(0, 7, 1000)), 'r--', 'LineWidth', 3);
grid on
export_fig test.png

generates:

This problem can be overcome by using the painters renderer. For example:

export_fig test.png -painters

used on the same figure generates:

Note that not only are the plot lines correct, but the grid lines are too.

Transparency - sometimes you might want a figure and axes' backgrounds to be transparent, so that you can see through them to a document (for example a presentation slide, with coloured or textured background) that the exported figure is placed in. To achieve this, first (optionally) set the axes' colour to 'none' prior to exporting, using:

set(gca, 'Color', 'none'); % Sets axes background

then use export_fig's -transparent option when exporting:

export_fig test.png -transparent

This will make the background transparent in PDF, EPS and PNG outputs. You can additionally save fully alpha-blended semi-transparent patch objects to the PNG format. For example:

logo;
alpha(0.5);

generates a figure like this:

If you then export this to PNG using the -transparent option you can then put the resulting image into, for example, a presentation slide with fancy, textured background, like so:

and the image blends seamlessly with the background.

Image quality - when publishing images of your results, you want them to look as good as possible. By default, when outputting to lossy file formats (PDF, EPS and JPEG), export_fig uses a high quality setting, i.e. low compression, for images, so little information is lost. This is in contrast to MATLAB's print and saveas functions, whose default quality settings are poor. For example:

A = im2double(imread('peppers.png'));
B = randn(ceil(size(A, 1)/6), ceil(size(A, 2)/6), 3) * 0.1;
B = cat(3, kron(B(:,:,1), ones(6)), kron(B(:,:,2), ones(6)), kron(B(:,:,3), ones(6)));
B = A + B(1:size(A, 1),1:size(A, 2),:);
imshow(B);
print -dpdf test.pdf

generates a PDF file, a sub-window of which looks (when zoomed in) like this:

while the command

export_fig test.pdf

on the same figure produces this:

While much better, the image still contains some compression artifacts (see the low level noise around the edge of the pepper). You may prefer to export with no artifacts at all, i.e. lossless compression. Alternatively, you might need a smaller file, and be willing to accept more compression. Either way, export_fig has an option that can suit your needs: -q<val>, where is a number from 0-100, will set the level of lossy image compression (again in PDF, EPS and JPEG outputs only; other formats are lossless), from high compression (0) to low compression/high quality (100). If you want lossless compression in any of those formats then specify a greater than 100. For example:

export_fig test.pdf -q101

again on the same figure, produces this:

Notice that all the noise has gone.

Tips

Anti-aliasing - the anti-aliasing which export_fig applies to bitmap outputs by default makes the images look nice, but it can also blur images and increase exporting time and memory requirements, so you might not always want it. You can set the level of anti-aliasing by using the -a<val> option, where is 1 (no anti-aliasing), 2, 3 (default) or 4 (maximum anti-aliasing).

Cropping - by default, export_fig crops its output to minimize the amount of empty space around the figure. If you'd prefer the figure to be uncropped, and instead have the same appearance (in terms of border width) as the on screen figure, then use the -nocrop option.

Colourspace - by default, export_fig generates files in the RGB colourspace. However, you can also export in greyscale or the CMYK colourspace, using the -grey (or -gray) and -cmyk options respectively. The CMYK option is useful for publishers who require documents in this colourspace, but the option is only supported for PDF, EPS and TIFF files.

Specifying a target directory - you can get export_fig to save output files to any directory (for which you have write permission), simply by specifying the full or relative path in the filename. For example:

export_fig ../subdir/fig.png;
export_fig('C:/Users/Me/Documents/figures/myfig', '-pdf', '-png');

Variable file names - often you might want to save a series of figures in a for loop, each with a different name. For this you can use the functional form of input arguments, i.e. export_fig(arg1, arg2), and construct the filename string in a variable. Here's an example of this:

for a = 1:5
    plot(rand(5, 2));
    export_fig(sprintf('plot%d.png', a));
end

When using the functional form like this, be sure to put string variables in quotes:

export_fig(sprintf('plot%d', a), '-a1', '-pdf', '-png');

Specifying the figure/axes - if you have multiple figures open you can specify which figure to export using its handle:

export_fig(figure_handle, filename);

Equally, if your figure contains several subplots then you can export just one of them by giving export_fig the handle to the relevant axes:

export_fig(axes_handle, filename);

Multiple formats - save time by exporting to multiple formats simultaneously. E.g.:

export_fig filename -pdf -eps -png -jpg -tiff

Other file formats - if you'd like to save your figure to a bitmap format that is not supported by export_fig, e.g. animated GIF, PPM file or a frame in a movie, then you can use export_fig to output the image, and optionally an alpha-matte, to the workspace. E.g.:

frame = export_fig;

or

[frame, alpha] = export_fig;

These variables can then be saved to other image formats using other functions, such as imwrite.

Appending to a file - you can use the -append option to append the figure to the end of an image/document, if it already exists. This is supported for PDF and TIFF files only. Note that if you wish to append a lot of figures consecutively to a PDF, it can be more efficient to save all the figures to PDF separately then append them all in one go at the end (e.g. using append_pdfs).

Output to clipboard - you can use the -clipboard option to copy the specified figure or axes to the system clipboard, for easy paste into other documents (e.g., Word or PowerPoint). Note that the image is copied in bitmap (not vector) format.

Font size - if you want to place an exported figure in a document with the font a particular size then you need to set the font to that size in the figure, and not resize the output of export_fig in the document. To avoid resizing, simply make sure that the on screen figure is the size you want the output to be in the document before exporting.

Renderers - MATLAB has three renderers for displaying and exporting figures: painters, OpenGL and ZBuffer. The different renderers have different features, so if you aren't happy with the result from one renderer try another. By default, vector formats (i.e. PDF and EPS outputs) use the painters renderer, while other formats use the OpenGL renderer. Non-default renderers can be selected by using one of these three export_fig input options: -painters, -opengl, -zbuffer:

export_fig test.png -painters

Artifacts - sometimes the output that you get from export_fig is not what you expected. If an output file contains artifacts that aren't in the on screen figure then make sure that the renderer used for rendering the figure on screen is the same as that used for exporting. To set the renderer used to display the figure, use:

set(figure_handle, 'Renderer', 'opengl');

After matching the two renderers, if the artifact appears in the on screen figure then you'll need to fix that before exporting. Alternatively you can try changing the renderer used by export_fig. Finally check that it isn't one of the known issues mentioned in the section below.

Smoothed/interpolated images in output PDF - if you produce a PDF using export_fig and images in the PDF look overly smoothed or interpolated, this is because the software you are using to view the PDF is smoothing or interpolating the image data. The image is not smoothed in the PDF file itself. If the software has an option to disable this feature, you should select it. Alternatively, use another PDF viewer that doesn't exhibit this problem.

Locating Ghostscript/pdftops - You may find a dialogue box appears when using export_fig, asking you to locate either Ghostscript or pdftops (part of the Xpdf package). These are separate applications which export_fig requires to perform certain functions. If such a dialogue appears it is because export_fig can't find the application automatically. This is because you either haven't installed it, or it isn't in the normal place. Make sure you install the applications correctly first. They can be downloaded from the following places:

  1. Ghostscript: www.ghostscript.com
  2. pdftops (install the Xpdf package): www.xpdfreader.com

If you choose to install them in a non-default location then point export_fig to this location using the dialogue box.

Undefined function errors - If you download and run export_fig and get an error similar to this:

??? Undefined function or method 'print2array' for input arguments of type 'double'.

then you are missing one or more of the files that come in the export_fig package. Make sure that you click the "Get from GitHub" button at the top-right of the download page, then extract all the files in the zip file to the same directory. You should then have all the necessary files.

Known issues

There are lots of problems with MATLAB's exporting functions, especially print. Export_fig is simply a glorified wrapper for MATLAB's print function, and doesn't solve all of its bugs (yet?). Some of the problems I know about are:

Fonts - when using the painters renderer, MATLAB can only export a small number of fonts, details of which can be found here. Export_fig attempts to correct font names in the resulting EPS file (up to a maximum of 11 different fonts in one figure), but this is not always guaranteed to work. In particular, the text positions will be affected. It also does not work for text blocks where the 'Interpreter' property is set to 'latex'.

Also, when using the painters renderer, ghostscript will sometimes throw an error such as Error: /undefined in /findfont. This suggests that ghostscript could not find a definition file for one of your fonts. One possible fix for this is to make sure the file EXPORT_FIG_PATH/.ignore/gs_font_path.txt exists and contains a list of paths to the folder(s) containing the necessary font definitions (make sure that they are TrueType definitions!), separated by a semicolon.

RGB color data not yet supported in Painter's mode - you will see this as a warning if you try to export a figure which contains patch objects whose face or vertex colors are specified as an RGB colour, rather than an index into the colormap, using the painters renderer (the default renderer for vector output). This problem can arise if you use pcolor, for example. This is a problem with MATLAB's painters renderer, which also affects print; there is currently no fix available in export_fig (other than to export to bitmap). The suggested workaround is to avoid colouring patches using RGB. First, try to use colours in the figure's colourmap (instructions here) - change the colourmap, if necessary. If you are using pcolor, try using uimagesc (on the file exchange) instead.

Dashed contour lines appear solid - when using the painters renderer, MATLAB cannot generate dashed lines using the contour function (either on screen or in exported PDF and EPS files). Details can be found here.

Text size - when using the OpenGL or ZBuffer renderers, large text can be resized relative to the figure when exporting at non-screen-resolution (including using anti-alising at screen resolution). This is a feature of MATLAB's print function. In this case, try using the -painters option.

Lighting and transparency - when using the painters renderer, transparency and lighting effects are not supported. Sorry, but this is an inherent feature of MATLAB's painters renderer. To find out more about the capabilities of each rendering method, see here. You can still export transparent objects to vector format (SVG) using the excellent plot2svg package, then convert this to PDF, for example using Inkscape. However, it can't handle lighting.

Lines in patch objects - when exporting patch objects to PDF using the painters renderer (default), sometimes the output can appear to have lines across the middle of rectangular patches; these lines are the colour of the background, as if there is a crack in the patch, allowing you to see through. This appears to be due to bugs in MATLAB's internal vector rendering code. These lines can often be removed from the PDF using software such as InkScape. Sometimes disabling anti-aliasing in the PDF-reader software can get rid of the lines (discussion).

Out of memory - if you run into memory issues when using export_fig, some ways to get round this are:

  1. Reduce the level of anti-aliasing.
  2. Reduce the size of the figure.
  3. Reduce the export resolution (dpi).
  4. Change the renderer to painters or ZBuffer.

Errors - the other common type of errors people get with export_fig are OpenGL errors. This isn't a fault of export_fig, but either a bug in MATLAB's print, or your graphics driver getting itself into a state. Always make sure your graphics driver is up-to-date. If it still doesn't work, try using the ZBuffer renderer.

Raising issues

If you think you have found a genuine error or issue with export_fig that is not listed above, first ensure that the figure looks correct on screen when rendered using the renderer that export_fig is set to use (e.g. if exporting to PDF or EPS, does the figure look correct on screen using the painters renderer, or if exporting to bitmap, does the figure look correct on screen using the OpenGL renderer?). If it looks wrong then the problem is there, and I cannot help (other than to suggest you try exporting using a different renderer).

Secondly, if exporting to bitmap, do try all the renderers (i.e. try the options -opengl, -zbuffer and -painters separately), to see if one of them does produce an acceptable output, and if so, use that.

If this still does not help, then ensure that you are using the latest version of export_fig, which is available here.

If the figure looks correct on screen, but an error exists in the exported output (which cannot be solved using a different renderer) then please feel free to raise an issue. Please be sure to include the .fig file, the export_fig command you use, the output you get, and a description of what you expected. I can't promise anything, but if it's easy to fix I may indeed do it. Often I will find that the error is due to a bug in MATLAB's print function, in which case I will suggest you submit it as a bug to TheMathWorks, and inform me of any fix they suggest. Also, if there's a feature you'd like that isn't supported please tell me what it is and I'll consider implementing it.

And finally...

If you've ever wondered what's going on in the logo on the export_fig download page (reproduced here), then this explanantion is for you. The logo is designed to demonstrate as many of export_fig's features as possible:

Given a figure containing a translucent mesh (top right), export_fig can export to pdf (bottom centre), which allows the figure to be zoomed-in without losing quality (because it's a vector graphic), but isn't able to reproduce the translucency. Also, depending on the PDF viewer program, small gaps appear between the patches, which are seen here as thin white lines.

By contrast, when exporting to png (top left), translucency is preserved (see how the graphic below shows through), and the figure is anti-aliased. However, zooming-in does not reveal more detail since png is a bitmap format. Also, lines appear less sharp than in the pdf output.

export_fig's People

Contributors

ahurlbatt avatar altmany avatar erihe251 avatar hyiltiz avatar jdonley avatar jonasstein avatar ojwoodford avatar readmecritic avatar scottclowe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

export_fig's Issues

Error in 2014b with OS X Yosemite

I recently upgraded to 2014b after upgrading to OS X Yosemite. When I try to save a figure, I get the following error:

Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
   dom   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2
   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
   %stopped_push   1900   1   3   %oparray_pop   1899   1   3   %oparray_pop   1883   1
   3   %oparray_pop   1771   1   3   %oparray_pop   --nostringval--   %errorexec_pop
   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push
   --nostringval--
Dictionary stack:
   --dict:1172/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Current file position is 64
GPL Ghostscript 9.07: Unrecoverable error, exit code 1


Error in export_fig (line 433)
        eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2,
        options.quality);

Do you have any ideas about what the problem is? Anyway, thanks for all your great work! I have been using export_fig for quite some time now and find it super duper helpful!!

NaN's error when using the -p option

Using either an integer or a percentage with the -p option, getting the following error on r2013b

    NaN's cannot be converted to logicals.

    Error in export_fig>parse_args (line 740)
            if options.bb_padding

    Error in export_fig (line 210)
                    [fig, options] = parse_args(nargout,
                    varargin{:});

Add option to disable/enable figure output

I really like export_fig, and I use it at as no-hassle solution to export figures from my scripts.
Currently I simply comment all export_fig calls when I just want to run my code without having to wait for Matlab to save all the figures โ€“ if export_fig took an optional boolean argument which determined whether to export the figure, or just ignore the call, this could be set using a single variable in the script.

I know this could be achieved putting if statements around all calls to export_fig, but it does clutter the otherwise minimalistic coding style which export_fig allows.
Albeit being considered really bad coding style, this could also be done using a global variable, which would make it even easier to temporarily disable export_fig.

I hope you'll consider my suggestions.

Grey boxes instead of text

Great tool. Small bug report. When exporting, sometimes text within the figure is replaced by grey boxes. Changing the resolution from 600 dpi to 300 dpi often fixes the problem (but not always). Using Matlab R2014b Pre-release.
pagerankscatter

bad export of transparent rectangle annotation

Reported by Kai Shi on FEX page on Feb 3, 2015:

I added a rectangle box in the figure and change the transparency of the box to 0.3. However, when I export the figure into latex. The transparency of the box is still 100%. With and without the -transparent option shows the same results. The code of generating the box is shown below:

annotation(hCCs, 'rectangle',rectSize, 'FaceColor','r', 'FaceAlpha',0.3, 'LineStyle','none');

Bug with PDF export in R2014b on MAC 10.10 Yosemite

Dear Oliver,
Would be great to have export_fig function properly on Matlab2014b.
I got the following response from Mathworks.

"The "export_fig.m" function was developed using the graphics system in MATLAB R2014a and earlier releases. The graphics in MATLAB R2014b was fundamentally rebuilt, which produces some incompatibilities with program written for earlier releases. The "Comments and Ratings" section in MATLAB Central for the "export_fig" function have already made note of this incompatibility; this can be seen in the following link:

http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig

Ghostscript error when calling eps2pdf

Export_fig has been a life saver. Thank you so much for posting it! I am sorry I accidently posted this bug report as a comment on the mathworks file exchange and am not sure how to take it down...Unfortunately, I now get the following error:
Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
dom --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push 1932 1 3
%oparray_pop 1931 1 3 %oparray_pop 1915 1 3
%oparray_pop 1803 1 3 %oparray_pop --nostringval--
%errorexec_pop .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:1189/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Current file position is 64
GPL Ghostscript 9.09: Unrecoverable error, exit code 1
Error in export_fig (line 424)
eps2pdf(tmp_nam, pdf_nam, 1, options.append,
options.colourspace==2, options.quality);

any ideas?

painters renderer not being recognized

On Matlab r2015a:

Very slow performance (or stuck in loop, not sure, wasn't patient enough) writing a figure to pdf. Looks like it's getting stuck in a while loop in print2eps.m around line 225, as it reads in the entire eps file line by line?

Figure has many lines (about 127 separate lines), looking in the temp folder, the eps file is about 6.6 MB.

I do not experience this issue on r2013b (I guess because of the thin line widths workaround you are doing in >=r2014b).

command:
export_fig(fname,'-pdf','-nocrop');

Attached figure file:
https://dl.dropboxusercontent.com/u/29498615/untitled.fig

Lines on Patch-Objects after *.EPS/PDF export - e.g. with contourf

I know that there are plenty of comments on strange lines appearing in exported matlab output, still I didn't really find out if there is already a solution to my specific problem.

About 3 years ago I exported a MATLAB contourf plot to *.eps with export_fig of ojwoodford. I guess it was MATLAB R2012a or b and the present version of export_fig those days. It worked perfectly and there were no strange atrifacts, whatsorever.
Yesterday I did the same with MATLAB R2014b and the current release of export_fig. Now I have strange artifacts when exporting to *.eps or *.pdf.

See the attached image (left: 3 years ago, right: yesterday - it's a different colormap and a different matrix of data, but this shouldn't be the problem...)
lines_in_contourf

Unfortunately those white lines are really present --> When I import the *.eps e.g. to Corel Technical Designer and further edit the image to do some tweaks for my presentation, these lines remain visible. After doing some editing and exporting from Corel Technical Designer to *.png or *.eps - I have the lines in both output formats...

Is there any solution to this problem?
Is it a bug or a feature?
Why did it work 3 years ago and now it doesn't anymore?

Is it the same issue that was already reported (#28) and ojwoodford responded that it is a bug, which will be fixed in the next MATLAB release: #28 ?? --> Because I just updated to MATLAB R2015a and to the latest export_fig release. The problem got not fixed...
Thanks for your help!

PS: In between I believe it is actually the anti aliasing... in adobe reader I can set a property (2D graphics accelaration) --> if switched on: the lines disappear. If turned off --> the lines reappear. But in most of the other programs (including GS viewer) I didn't manage to get rid of those lines. Actually the lines obstruct further editing in some third party software outside of MATLAB... and I don't get why I did not have those lines when exporting three years ago... I checked my *.eps files from then: no lines at all in none of the figures I exported then (neither in GS viewer nor in third party software...) --> So why do those lines appear now??

Problem with 'color','none' in R2014b and with whitespace at top of graph

Hi. I noticed export_fig crashes when a line with color set to 'none' is used in R2014b.
export_fig and ghostscript are up-to-date and my computer is Windows 7 64 bit.

Here is the error message:

Warning: File 'C:\Users\Brian\AppData\Local\Temp\tpbe560a33_bda5_4bee_8219_3c3eb53f6202.eps' not found.
In export_fig at 445
In testcase at 10
Error using cell2mat (line 45)
All contents of the input cell array must be of the same data type.

Error in print2eps (line 161)
M = cell2mat(M);

Error in export_fig (line 428)
print2eps(tmp_nam, fig, options.bb_padding, p2eArgs{:});

Error in testcase (line 10)
export_fig .pdf

The following code will generate the error:

line(nan,nan)
line(nan,nan,'color','none')
export_fig .pdf

Looking at print2eps.m, the line M = get(white_line_handles, 'Color'); creates a cell containing both doubles and the string 'none', causing the cell2mat error.
Placing M(strcmp('none',M))={[]}; prior to the cell2mat call seems to solve the problem.

The second issue is that when the ylabel is a long string with large fontsize, the whitespace at the top is not correctly cropped, though it is fine on the other sides.

Here's the code:

plot(sin(0:1:10))
ylabel('aaaaaaaaaaaaaaaaaaa','fontsize',50)
export_fig .pdf

Thanks so much for writing such a helpful script!

axes grid lines disappear when using -cmyk

I have a figure with a semilogy axis. I enable grid lines and things look good in matlab, but the grid lines do not appear in the exported PDF. I am using the command "export_fig ccdf.pdf -p2 -cmyk -transparent". I've attached an output image (converted to PNG from PDF)---note the lack of grid lines.

Here is a link to my fig file (warning ~20MB): http://cs.unc.edu/~gelliott/ccdf.fig.zip

I am using OS X Yosemite with matlab 2014b.

ccdf

2014b and area graphs

Hi,

since 2014b area graphs look strange ("striped") when exporting with the default renderer. Opengl works, but creates very large files. (Also the clipping of is different.) Any way out of this?

See example below. /Paul Sรถderlind

ha = figure;
x = linspace(-pi,pi,101)';
area(x,cos(x),'FaceColor',[1,0.2,0.2]);
title('my title')
ylabel('y')
xlabel('x')
export_fig('-pdf',ha,'areaTest2a.pdf');
export_fig('-pdf','-opengl',ha,'areaTest2b.pdf');

Annotation units

I have found a minor bug when the units of a figure annotation are set to 'pixels' instead of 'normalized'.

Consider this working example:

set(gcf,'position',[0 0 280 280])
set(gca,'position',[0.1 0.1 0.8 0.8])

% circle at origin
plot(0,0,'ko','markersize',60)

% cross centered at origin
hAn(1) = annotation('line',[0.4 0.6],[0.4 0.6]);
hAn(2) = annotation('line',[0.4 0.6],[0.6 0.4]);
export_fig('fig1-units-normalized.png')

% change annotation units (this does not actually alter the appearance of the figure)
set(hAn,'units','pixels')
export_fig('fig2-units-pixels.png')

% restore annotation units
set(hAn,'units','normalized')
export_fig('fig3-units-normalized.png')

Font issue on Yosemite / Matlab 2014b, 2015a

Hi Oliver,

Thanks for this great cotribution. Export_fig is super important to me. Unfortunately, it seems the font problem is back under Yosemite and Matlab 2014b. I use the newest version of your routines.

I run into problems whenever I try to export a plot that extend to large numbers such that "10^5" or similar is shown on the axis. I hope the example below helps tracking down the problem. Can you please look into this?

Do you know when you can have a look at this? Export_fig is crucial for my work.

Thanks,
Bjรถrn

Example:

plot(1,1); export_fig('test.eps',gcf);

---> Works fine

plot(100000,100000); export_fig('test.pdf',gcf);

---> gives the following error message

Error using eps2pdf (line 107)
Error: /undefined in definefont
Operand stack:
CMSY10 --dict:14/15(L)-- Font
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push
--nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1951 1 3
%oparray_pop 1950 1 3 %oparray_pop --nostringval-- 1934 1 3 %oparray_pop 1820
1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval--
--nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 1901 2 3
%oparray_pop
Dictionary stack:
--dict:1188/1684(ro)(G)-- --dict:0/20(G)-- --dict:121/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 71147
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 442)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

Error in savefigure (line 40)
export_fig([filename '.eps'],hfig);

Exported figure in PDF too much cropped from original figure

test_figure
Hello,

Thanks a lot for providing your code. My issue could be similar to the one posted in #32. However, unlike the author of that post, my exported figure in PDF is getting too much cropped. That means, the exported PDF figure is somewhat smaller than original .fig or .png file.

I am using Matlab R2014a and latest export_fig code of http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig

I tried with the following simple code and this issue persisted:

figure(1)
plot(1:100,1:100)
xlabel('Frequency (Hz)')
ylabel('attenuation (Neper/m)')
set(gca,'fontsize',16)
export_fig test -pdf -transparent

Attached figure shows how the exported pdf figure looks like.

Your feedback will be very appreciated.

Thanks,

Nazmul

A totally same code, Why I didn't get so smooth figure?

I copy the code:
plot(cos(linspace(0, 7, 1000)));
set(gcf, 'Position', [100 100 150 150]);
saveas(gcf, 'test.png');
export_fig test2.png

But I get the figure not smooth as you get.
we get the figure like in this link:
(https://github.com/altmany/export_fig)
in this link, there are "example", there are 3 figures, Figure, test.png, test2.png you made.
Our figure was like the first Figure, Although I copy your code totally the same, but I can't get so smooth figure. Why? What's the reason?

Using export_fig with FaceAlpha on Unix through SSH connection

Hello,
I am new to GitHub and I hope I submit this issue in the right way.

Here is a description of my problem : I am running MATLAB 2012a on a Unix distant computer through a SSH connection. I am trying to execute a script which produces figures with patches including transparency (set with the FaceAlpha patch property) and exports the figures with export_fig. When I call export_fig, I get the following errors :

Error using print>LocalPrint (line 295)
Bad data returned by HARDCOPY. Not calling IMWRITE.
Error in print (line 237)
LocalPrint(pj);
Error in print2array (line 140)
print(fig, renderer, res_str, '-dtiff', tmp_nam);
Error in export_fig (line 334)
[A, tcol] = print2array(fig, magnify, renderer);

I use the default renderer (OpengGL), which is supposed to support transparency.
The problem does not occur when I set the FaceAlpha of the patch to 1.
The problem also doesn't occur when I run the script on my Windows machine.
If the information may be useful : the X11 forwarding seems to work OK since I can see MATLAB's desktop (graphical interface).

Any ideas?

Feature request: Convert embedded font in PDF to curves

Strange things happen, if the user wants to postprocess a PDF with embedded fonts and the system can not find the right font.

Ghostscript 9.15 supports converting text to curves with
gs -o curves.pdf -dNoOutputFonts -sDEVICE=embedded.pdf

I suggest to add this as option for pdf export.

ps: Thanks a lot for export_fig.

Exporting bold TeX symbols to EPS/PDF in R2014b

Before I upgraded to 2014b, I could save figures with TeX symbols (e.g., \gamma or \beta) in the labels of figures and the output figure would contain the symbols as I expected. However, since I've upgraded to 2014b and then upgraded my export_fig package, I am now getting dots in place of the TeX symbols in the output figure files. Does anyone know why this is happening and how to fix it?

Thanks so much!

Ghostscript error: /rangecheck in definefont

Reported by Jean on Feb 24, 2015:

I have the same issue as James Rankin in Matlab R2014b:

Error using eps2pdf (line 107) 
Error: /rangecheck in definefont 
Operand stack: 
   CMMI10 --dict:14/15(L)-- Font 
Execution stack: 
   %interp_exit .runexec2 --nostringval-- --nostringval-- 
   --nostringval-- 2 %stopped_push --nostringval-- 
   --nostringval-- --nostringval-- false 1 %stopped_push 
   1951 1 3 %oparray_pop 1950 1 3 %oparray_pop 
   --nostringval-- 1934 1 3 %oparray_pop 1820 1 3 
   %oparray_pop --nostringval-- %errorexec_pop .runexec2 
   --nostringval-- --nostringval-- --nostringval-- 2 
   %stopped_push --nostringval-- 1901 2 3 %oparray_pop 
Dictionary stack: 
   --dict:1188/1684(ro)(G)-- --dict:0/20(G)-- --dict:121/200(L)-- 
Current allocation mode is local 
Last OS error: Invalid argument 
Current file position is 90501 
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 442) 
        eps2pdf(tmp_nam, pdf_nam, 1, options.append, 
        options.colourspace==2, options.quality);

Error in fit_ramsey (line 210) 
export_fig(['fit_' filename], '-pdf');

Unfortunately, his fix is not working for me... It was working well with 2012b, I don't understand, as I am working with standard fonts...

Unable to perform post-processing due to index out of bounds

I pulled the latest version of export_fig today, I get the following warning if I export to pdf or eps:

Warning: Loading EPS file failed, so unable to perform post-processing. This is usually because the figure contains a large number of patch objects. Consider exporting to a bitmap format in this case.
In print2eps at 229
In export_fig at 480

The result is a pdf file with a lot of useless whitespace (probably because of failure of the post-processing). If I step through 'print2eps.m' with the MATLAB Debugger, I get an 'Index exceeds matrix dimensions' error in line 192. Is this a newly introduced bug? I never saw this warning before.

tex symbols

Hi,
I'm still a bit puzzled how to display tex symbols. For instance, one of my titles is
title('\pi^w')
and is properly displayed in the figure, but not the printed pdf (there, I get a colon to the power of w). I'm using the latest version of texshop 3.49.
Thanks!

Ghostscript Installation on Network Drive Option

It would be nice if Ghostscript.m would allow you to specify an alternate location for a ghostview executable. This could be an optional variable, such as "gs_exec" that could get sent to export_fig. It would be preferable if the variable could be a vector or list of strings so that you could provide it multiple locations. This is required when different users have access to different network drives depending on their location in your company. The idea is that if a user doesn't have ghostview installed, we could install ghostview on a network drive and point export_fig to this executable instead of forcing all users to install ghostview. This approach would be preferrable over a file-selection dialog window (such as pdftops) that informs the user if they don't have ghostview installed because in that scenario the user must know exactly where the ghostview installation is located on a network drive and they must keep answering this same question every time they use software which uses export_fig.

Export_Fig trouble with .eps and 'FaceAlpha'

First off, I love your toolbox and use it constantly. I have recently run into an issue exporting .eps files that have 'FaceAlpha' values. These boxes just seem to disappear and it seems that the title is not lined up. The image exports fine under .jpg.

Here is the .eps file: https://www.dropbox.com/s/dbdr9u8gh69h5x8/Boxes3.eps?dl=0
Here is the .jpg file: https://www.dropbox.com/s/yaxi3b5oto7hzf3/Boxes.jpg?dl=0
Here is the .m file: https://www.dropbox.com/s/wqew64a9h6aufvp/Object_Step_Size_Changes.m?dl=0

All commands in the MATLAB .m file should be native to any version. The only toolbox added is yours.

I tried to add the -painters just in case and it does not seem to make a difference. Also tried print2eps as well as export_fig.

Any help is greatly appreciated.

Best
Corbin

Possible problem with '-transparent' option when exporting resized figure in latest version

I've been using your script for years with my same code, no troubles with MATLAB v2009b, but I got a new PC with MATLAB v2012b, and that's when troubles began.
I downloaded the latest version on 11/4/2014. The first error I had went away, but now I have this other error.

First, I am creating a figure and resizing it to fit the screen with the following code:
h=figure;
set(h, 'Position', get(0,'ScreenSize'));

Then, later in my code, I call the export_fig function as such:
export_fig(strcat(dirname,'',sn,fname,'.png'),'-png','-transparent',h);

And, this is the error I receive:

Array dimensions must match for binary array op.

Error in export_fig (line 283)
alpha = round(sum(B - A, 3)) / (255 * 3) + 1;

Error in SavePlotsFnc (line 3)
export_fig(strcat(dirname,'',sn,fname,'.png'),'-png','-transparent',h);

Let me know if you require any additional information.
Thank you in advance for your help.

R2014b - Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts

The following code is working:
export_fig([savepath,'bw',savefilename,'_BW_XL_cropped'],...
'-png', '-q101', '-GRAY', '-m3');
while this code is not:
export_fig([savepath,'bw',savefilename,'_BW_XL_cropped'],...
'-png', '-transparent', '-q101', '-GRAY', '-m3');

it results in the following error:

export_fig error. Please ensure:
[...] If the problem persists, then please report a new issue.

Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts
Error in export_fig (line 353)
B(vB(1):vB(2), vB(3):vB(4), :) = A(vA(1):vA(2), vA(3):vA(4), :); %
ADDED BY OH

Independent of the path: The only difference is the transparent option --> why is that a problem?

Error: 'Units' is not an accessible property

Recently updated export_fig, using version 27/03/15. Simple call to export_fig, now getting the following error:

Can supply .fig file if that's helpful.

from calling:
export_fig('figures\strouhal\bat1.pdf','-pdf')

    Error using hg.hggroup/get
    The name 'Units' is not an accessible property
    for an instance of class 'hggroup'.

    Error in export_fig (line 282)
                            originalUnits =
                            get(annotationHandles,'Units');

Plot markers on axis are missing in EPS output (R2014B, win7, GS9.15)

working eps via 'print':
working eps
broken eps via 'export_fig':
broken eps

%steps to reproduce:
x=[ 0 NaN NaN NaN NaN 0.5283 NaN NaN NaN NaN];
y = [ 1 NaN NaN NaN NaN 0 NaN NaN NaN NaN ];
%plot graph which has 2 markers on the axes
figure, plot(x,y,'marker','o')
%generate a working eps file which has markers on the x- and y- axes at the appropriate points
print -depsc2 -r864 -painters working.eps
% export_fig's eps file has no markers shown on the axes.
export_fig broken.eps
%expected behaviour: both EPS files should show 2 points on the graph
%actual behaviour: export_fig's EPS file shows no points on the graph

This occurs under MATLAB R2014 b on windows, 64bit , ghostscript 9.15, using latest export_fig from github.
I think this is related to the bug where objects on axes in 3D plots are not printed:
https://www.mathworks.com/support/bugreports/946762
However this is a 2D plot and "print" on its own works. (Is export_fig converting figures to 3D?)

Line joins are spikey in vector output using R2014b

I am plotting country borders from a shapefile with the default LineWidth. In Matlab 2014a, export_fig outputs these at the correct width, but it doesn't work properly in 2014b. I use exactly the same code in the two different versions. In the Figure window, these are plotted exactly the same; the differences only occur in the exported figure. These images show the difference between the two:
2014a:
2014a

2014b:
2014b

eps & pdf export not working on Mac 10.10.2 and Matlab R2014b

when I try to export a figure to eps, ps or pdf I get the following error:

>> plot([0 100]*1e10,[0 100]*1e10,'-b')
>> export_fig test.eps
Error: /undefined in Infinity
Operand stack:
   --nostringval--   560   0   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1951   1   3   %oparray_pop   1950   1   3   %oparray_pop   --nostringval--   1934   1   3   %oparray_pop   1820   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1179/1684(ro)(G)--   --dict:0/20(G)--   --dict:121/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 9496
GPL Ghostscript 9.15: Unrecoverable error, exit code 1
Ghostscript error: perhaps /private/tmp/tp0576f1d3_2479_440d_ac55_425c20a76e9c.pdf is open by some other application
export_fig error. Please ensure:
  that you are using the latest version of export_fig
  and that you have Ghostscript installed
  and that you have pdftops installed
  and that you do not have multiple versions of export_fig installed by mistake
  and that you did not made a mistake in the expected input arguments

If the problem persists, then please report a new issue.

Error using eps2pdf (line 149)
Error: /undefined in Infinity
Operand stack:
   --nostringval--   560   0   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
   %stopped_push   1951   1   3   %oparray_pop   1950   1   3   %oparray_pop   --nostringval--   1934   1   3   %oparray_pop   1820   1   3   %oparray_pop   --nostringval--
   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1188/1684(ro)(G)--   --dict:0/20(G)--   --dict:121/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 9496
GPL Ghostscript 9.15: Unrecoverable error, exit code 1


Error in export_fig (line 512)
                eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality, options.gs_options);

Error appending to pdf

When I try to append to a pdf (with code that worked in before upgrade to 2014b) I get the following error (the first plot works, this is for the appended one).

Error using eps2pdf (line 107)
Error: /undefined in definefont
Operand stack:
CMSY10 --dict:14/15(L)-- Font
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2
%stopped_push --nostringval-- --nostringval-- --nostringval-- false 1
%stopped_push 1951 1 3 %oparray_pop 1950 1 3 %oparray_pop
--nostringval-- 1934 1 3 %oparray_pop 1820 1 3 %oparray_pop
--nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval-- 1901 2 3 %oparray_pop
Dictionary stack:
--dict:1188/1684(ro)(G)-- --dict:1/20(G)-- --dict:121/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 150864
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 435)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2,
options.quality);

Error in rayToemRealAD (line 469)
export_fig(oemFile, '-pdf', '-append', '-nocrop')

Problem with imagesc when exporting to PDF/EPS

Hello, I am happy and frequent user of export_fig for several years, but I have encountered a problem when exporting figures created using the imagesc command to PDF or EPS (vector graphics). I can reproduce the problem using the following code:

x = 0.025:0.025:(1-0.025);
y = (1:25)_128/3228;
Z = rand(length(y),length(x));
figure
imagesc(x,y,Z)
colormap gray
axis xy
axis([0,1,0,1])
hold on
xx = linspace(0,1,1001);
yy = min(y)_ones(size(xx));
dy = diff(y);
dy = dy(1);
plot(xx,yy+dy/2,'-r')
export_fig('fig.pdf')

The figure in Matlab (attached) is looking as I would expect: the red line is exactly between rows of pixels. But after exporting to PDF (also attached) the red line is no longer between rows of pixels and the bottom row of pixels seems truncated/cropped from below. It seems that the the image has been moved down relative to the red line and truncated/cropped. Any ideas what goes wrong?

Thanks,
Jakob

figure_in_matlab
figure_exported_to_pdf

Errors with export_fig on R2014b, Yosemite, GS 9.15

Hi Oliver,

The following and similar errors appear to be common on the mathworks thread:

Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
dom --nostringval--
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push 1951 1 3 %oparray_pop 1950 1 3 %oparray_pop 1934 1 3 %oparray_pop 1820 1 3
%oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:1188/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 64
GPL Ghostscript 9.15: Unrecoverable error, exit code 1

Error in export_fig (line 433)
eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

eps and pdf export not working in Matlab R2014b on Ubuntu 14.04

png export is wortking properly. When I try to export to pdf or eps, I get the following error message:

>> export_fig 'filename' '-pdf'
Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
   dom   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
   %stopped_push   1916   1   3   %oparray_pop   1915   1   3   %oparray_pop   1899   1   3   %oparray_pop   1787   1   3   %oparray_pop   --nostringval--   %errorexec_pop
   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1184/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Current file position is 64
GPL Ghostscript 9.10: Unrecoverable error, exit code 1


Error in export_fig (line 431)
        eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);


>> export_fig 'filename' '-eps'
Error using eps2pdf (line 107)
Error: /undefined in bdef
Operand stack:
   dom   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1
   %stopped_push   1916   1   3   %oparray_pop   1915   1   3   %oparray_pop   1899   1   3   %oparray_pop   1787   1   3   %oparray_pop   --nostringval--   %errorexec_pop
   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1184/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Current file position is 64
GPL Ghostscript 9.10: Unrecoverable error, exit code 1


Error in export_fig (line 431)
        eps2pdf(tmp_nam, pdf_nam, 1, options.append, options.colourspace==2, options.quality);

Figure is uncropped when exporting to pdf in MatlabR2014b (with the latest export_fig)

Hi,

First thanks a lot for providing such a wonderful toolbox!

However, here I've found a bug when I switch to Matlab 2014b. In Matlab R2014b, when I was using the toolbox to generate pdf figure as:

export_fig test -pdf -transparent

The margin of the figure is not cropped as desired. Could you have a look at it?

Thanks!

Example code:
figure(1)
plot(1:100,1:100)
xlabel('Frequency (Hz)')
ylabel('attenuation (Neper/m)')
set(gca,'fontsize',16)
export_fig test -pdf -transparent

capture

Using path variable when export_fig?

Is there any way to use path variable when export_fig? Consider this as a feature request if not. Thanks.

To be clear, I want to do like this:

path = sprintf('%s/%03d', folder, idx);
export_fig path -png

Legends cause problems with HG2

If there is a legend in a figure and HG2 is enabled, the following error pops up:

Error using hg2.Group/get
There is no XLimMode property on the Legend class.
Error in export_fig (line 215)
    Xlims = make_cell(get(Hlims, 'XLimMode'));

Greek letters in axis title. exporting to pdf.

When exporting figures with Greek letters (only with lowercase Lambda so far) in an axis title to PDF, the Greek letters do not display properly in the resulting PDF. Lowercase Lambda is showing up as the number 6. Using MATLAB 2014b and Ghostscript 9.15.

R2014b, ghostscript 9.15, mac

FYI export_fig crashes matlab on Yosemite, gs 9.15, latest export_fig. Similar result for export as png. Simple xy plot with 2 vectors of 62 elements.

pdf export:

load O3data2.mat
plot(O3den,zO3den)
export_fig ~./Desktop/aplot


   Segmentation violation detected at Mon Oct 27 11:15:21 2014

Configuration:
Crash Decoding : Disabled
Current Visual : Quartz
Default Encoding : ISO-8859-1
MATLAB Architecture: maci64
MATLAB Root : /Applications/MATLAB_R2014b.app
MATLAB Version : 8.4.0.150421 (R2014b)
Operating System : Darwin 14.0.0 Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Processor ID : x86 Family 6 Model 69 Stepping 1, GenuineIntel
Software OpenGL : 0
Virtual Machine : Java 1.7.0_55-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
Window System : Quartz

Fault Count: 1

Abnormal termination:
Segmentation violation

Another Yosemite error

I'm running Mac OS X 10.10.1, MATLAB R2014b, the latest version of export_fig (the one from a few days ago), Ghostscript 9.15, and xpdf 3.04. Here's what happens for me:

>> figure ; plot([0 100],[0 100],'-b')
>> export_fig ~/Desktop/test3.eps
Warning: File '/private/tmp/tpc9226e7e_20fb_4c28_a3f8_3a30467a05f3.eps' not found. 
> In export_fig at 445 
Error using checkArgsForHandleToPrint>LocalCheckHandles (line 88)
MATLAB Graphics handle must be a figure.

Error in checkArgsForHandleToPrint (line 30)



Error in print>LocalCreatePrintJob (line 336)
    handles = checkArgsForHandleToPrint(0, varargin{:});

Error in print (line 153)
    [pj, inputargs] = LocalCreatePrintJob(varargin{:});

Error in print2eps (line 144)
print(fig, options{:}, name);


Error in export_fig (line 428)
        print2eps(tmp_nam, fig, options.bb_padding, p2eArgs{:});

When I print using MATLAB's built-in function, it works (even with the modification you suggested to someone else):

>> print -depsc2 ~/Desktop/test.eps
>> set(gcf, 'PaperPositionMode', 'auto', 'InvertHardcopy', 'off');
>> print -depsc2 ~/Desktop/test2.eps

That warning is pretty weird. Any ideas? I know you are basically unable to support this, but I can try any suggestions you might have.

problems with eps2pdf in export_fig

I tried your code under Ubunutu 14.04 with Matlab2014R and get permanently the same error:

'Error using eps2pdf (line 107)
gs:
/usr/local/MATLAB/R2014a/bin/glnxa64/libtiff.so.5:
no version information available (required
by /usr/lib/libgs.so.9)
Error: /undefined in /findfont
Operand stack:
120 Times-Roman ISOLatin1Encoding
Times-Roman Times-Roman
Execution stack:
%interp_exit .runexec2
--nostringval-- --nostringval--
--nostringval-- 2 %stopped_push
--nostringval-- --nostringval--
--nostringval-- false 1
%stopped_push 1916 1 3
%oparray_pop 1915 1 3
%oparray_pop --nostringval-- 1899 1
3 %oparray_pop 1787 1 3
%oparray_pop --nostringval--
%errorexec_pop .runexec2
--nostringval-- --nostringval--
--nostringval-- 2 %stopped_push
--nostringval-- --nostringval--
--nostringval-- 1868 5 5
%oparray_pop
Dictionary stack:
--dict:1184/1684(ro)(G)--
--dict:0/20(G)-- --dict:82/200(L)--
--dict:97/160(L)-- --dict:8/85(L)--
Current allocation mode is local
Current file position is 7064
GPL Ghostscript 9.10: Unrecoverable error,
exit code 1

Error in export_fig (line 406)
eps2pdf(tmp_nam, pdf_nam, 1,
options.append,
options.colourspace==2,
options.quality);
'

I dont know where the problem is located but i hope you can help me.

Best wishes

Tobi1986

Problem with white lines when exporting a figure containing multiple subplots

Hello,

When exporting a figure containing multiple subplots with white lines, only the white lines of the first subplot are exported in the correct color.
This is related to the Matlab bug when printing white lines : when commenting line 165 of of print2eps code, none of the line in the figure are white.
This happens irrespective of the output format (vectorized or bitmap), or of the renderer.
ssttom15trials_sample1_recurrent_cmaps

Graph is cut into when exported as pdf

Since the update of 2014b the exported figures are cut into which looks like this:

matlab

The command I use is:

export_fig -pdf

Am I the only one experiencing this?
[I also had to reinstall some stuff, ghostscript included, so maybe that's the source of error]

(working on Mac OS X 10.8.5)

bad export of box-less legend

Reported by Durga Lal Shrestha on Feb 9, 2015:

I have the legend at the Southoutside with horizontal orientation. When the box of the legend is set to 'off', a little bit bottom part of the legend is also cropped when exporting figure to eps and pdf (no problem with png). There is a no problem with box outline. The problem persists in MATLAB R2014b.

plot(1:10); 
h=legend('line','location','Southoutside');
set(h,'Box','off');
export_fig test.eps; 
winopen test.eps

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.