altmany / export_fig

A MATLAB toolbox for exporting publication quality figures
BSD 3-Clause "New" or "Revised" License
1.27k stars 365 forks source link

Blank files when using M1-based macOS #350

Closed hirothreading closed 2 years ago

hirothreading commented 2 years ago

Not sure if anyone else has ran into this issue, but when attempting to use export_fig on my M1 MacBook Air I just get a bunch of blank files (see attachment). Is this simply a compatibility issue when running MATLAB in Rosetta 2?

FWIW, I have no issues on my Intel-based Mac.

Screenshot 2022-01-30 at 13 33 56
altmany commented 2 years ago

Try to reinstall Ghostscript

yaohengkai commented 2 years ago

I'm facing a similar error. the output .png file is totally nothing. All output file has an exactly 107b size. I'm using MBP2021 m1 max, with MATLAB R2021b, the version of export_fig is 3.21 I tried install Ghostscript “Ghostscript-9.55-Full.pkg” from 'http://pages.uoregon.edu/koch'. The problem is still.

截屏2022-02-01 10 56 29
hirothreading commented 2 years ago

Installed GhostScript, but still getting the same issues

samsrabin commented 2 years ago

Same problem here. It's not every figure, but it is most of them. I've tried reinstalling ghostscript; no luck.

Bart-VZ commented 2 years ago

Same issue here on M1 Air. I've played around with the gcf color set because I first thought the script was somehow coloring the entire figure white and in doing so found that the figures/files to which this happens will arbitrarily shift. Giving the transparent option however always results in an empty file of size 107B, as stated before.

altmany commented 2 years ago

Try to run export_fig using the software emulation of opengl and see if this resolves the problem:

opengl software  % temporarily switch to opengl emulation mode
export_fig(...);
opengl hardware  % switch back to using opengl hardware acceleration
Bart-VZ commented 2 years ago

Try to run export_fig using the software emulation of opengl and see if this resolves the problem:

opengl software  % temporarily switch to opengl emulation mode
export_fig(...);
opengl hardware  % switch back to using opengl hardware acceleration

I have done as you suggested, but Matlab returns the following error:

Error using opengl Switching to software OpenGL rendering is not supported on the Mac platform.

altmany commented 2 years ago

Try the following and let me know what you see:

  1. use export_fig to save to EPS format and check whether you also get an empty file as with PDF
  2. run the following script and tell me if you see a good EPS file in your temp folder for any of the alternatives, or if all alternatives generate empty files as well:
    print2eps([tempdir '/check1.eps'], gcf);  % alternative 1
    print(gcf, '-loose', '-depsc2', [tempdir '/check2.eps']);  % alternative 2
    print(gcf, '-loose', '-painters', '-r864', '-depsc2', [tempdir '/check3.eps']);  % alternative 3
Bart-VZ commented 2 years ago

I saved to EPS using export_fig command and got a 0.58MB file with nothing but a few white pixels in it. I've attached it for your viewing pleasure (zipped because .eps is not natively supported by GitHub).

All of the alternative commands you offered did work successfully and gave the expected image! 1 & 2 gave a 1.1MB file, 3 was 0.2MB. Would love to be able to export as PNGs though :)

Thank you for your help and responsiveness!

check0.eps.zip

altmany commented 2 years ago

This is possibly the same problem as issues #318, #351 - try to modify the pause duration in print2eps.m line 543 from 0.02 to 0.1 or 0.2 and check if this resolves the problem.

altmany commented 2 years ago

I uploaded v3.25 that hopefully resolves the problem on all systems/releases, without a large performance penalty in the common case. I'm closing the issue, but if you find that v3.25 still does not solve the issue then let me know and I'll reopen it.