Problem using print('-dpng', '-r300', 'file.png') to write plot to disk in PNG format

Here's the chunk of code:
FigHandle = figure('Position', [100, 100, 1920, 700]);
subplot(121);
imagesc(X, Z, final_model_it_xz);
hold on;
set(line([17,33,33,17,17]*200 - 200, [12,12,13.5,13.5,12]*200 - 200), 'linewidth', 2, 'color', 'w');
hold off;
grid on;
set(gca, 'linewidth', 1, 'fontsize', 12);
h = colorbar();
set(get(h, 'title'), 'string', 'S$\cdot$ m$^{-1}$', 'fontsize', 12, 'interpreter', 'latex');
xlabel('Inline [m]', 'fontsize', 14, 'interpreter', 'latex');
ylabel('Depth [m]', 'fontsize', 14, 'interpreter', 'latex');
title_str = sprintf(['$\\mathbf{m}_{%d}$ at %g m without regularization',...
' with $\\min(\\mathbf{m}_{%d}) = %g$'], it, Y(iy), it, min_conductivity_it);
title(title_str, 'fontsize', 14, 'interpreter', 'latex');
print('-dpng', '-r300', [plot_folder,'modelYZ']);
subplot(122);
imagesc(Y, Z, final_model_it_yz);
hold on;
set(line([17,33,33,17,17]*200 - 200, [12,12,13.5,13.5,12]*200 - 200), 'linewidth', 2, 'color', 'w');
hold off;
grid on;
set(gca, 'linewidth', 1, 'fontsize', 12);
h = colorbar();
set(get(h, 'title'), 'string', 'S$\cdot$ m$^{-1}$', 'fontsize', 12, 'interpreter', 'latex');
xlabel('Crossline [m]', 'fontsize', 14, 'interpreter', 'latex');
ylabel('Depth [m]', 'fontsize', 14, 'interpreter', 'latex');
title_str = sprintf(['$\\mathbf{m}_{%d}$ at %g m without regularization',...
' with $\\min(\\mathbf{m}_{%d}) = %g$'], it, X(ix), it, min_conductivity_it);
title(title_str, 'fontsize', 14, 'interpreter', 'latex');
print('-dpng', '-r300', [plot_folder,'modelXZ']);
Here's what I see in the graphics windows:
Here's what ends up stored in my computer:
I am using:
>> version
ans =
8.5.0.197613 (R2015a)
Any hints?
Also, when I use the Save as... dialog from the figure viewer:
I get a perfect result:

7 comentarios

It sure has messed up the font size!
I would be curious to know if adding the -painters option changes anything?
Which MATLAB version are you using?
>> version
ans =
8.5.0.197613 (R2015a)
I have tried '-painters'. Did not work.
Wow. Trying FigHandle.PaperPosition=[100,100,1920,700 ]; yielded:
MATLAB crash file:/home/esanchez/matlab_crash_dump.31825-1:
------------------------------------------------------------------------
Segmentation violation detected at Mon Oct 16 14:04:56 2017
------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled
Crash Mode : continue (default)
Current Graphics Driver: Intel Open Source Technology Center Mesa DRI
Intel(R) Haswell Mobile Version 3.0 Mesa 10.3.7
Current Visual : 0x20 (class 4, depth 24)
Default Encoding : UTF-8
GNU C Library : 2.22 stable
Host Name : linux-d7wq.site
MATLAB Architecture : glnxa64
MATLAB Root : /home/esanchez/Software/MATLAB_R2015a
MATLAB Version : 8.5.0.197613 (R2015a)
OpenGL : hardware
Operating System : Linux 3.16.7-53-desktop #1 SMP PREEMPT Fri Dec 2
13:19:28 UTC 2016 (7b4a1f9) x86_64
Processor ID : x86 Family 6 Model 69 Stepping 1, GenuineIntel
Virtual Machine : Java 1.7.0_121-b00 with Oracle Corporation OpenJDK
64-Bit Server VM mixed mode
Window System : The X.Org Foundation (11601000), display :0
Fault Count: 1
Abnormal termination:
Segmentation violation
Register State (from fault):
RAX = 00007fe8dabde804 RBX = 00007fe8cdf019d8
RCX = 00007fe8f0b7c2c0 RDX = 00007fe8dabe40a0
RSP = 00007fe877ef9b90 RBP = 00007fe877ef9bc0
RSI = 0000000000000000 RDI = 00007fe8cdf01800
R8 = 0000000000000d6f R9 = 00007fe868000078
R10 = 00007fe868000070 R11 = 00007fe8f072fe70
R12 = 00007fe8cdf01800 R13 = 0000000000000000
R14 = 0000000000000000 R15 = 0000000000027776
RIP = 00007fe8da3f502a EFL = 0000000000010206
CS = 0033 FS = 0000 GS = 0000
Stack Trace (from fault):
[ 0] 0x00007fe8da3f502a
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06266922
[ 1] 0x00007fe8daeed68c
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libmwjmi.so+00935564
_Z23mljGetByteArrayElementsP8_jobject+00000044
[ 2] 0x00007fe874ba78ed
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libuij.so+00256237
[ 3] 0x00007fe8e4f0a01d
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libmwgui.so+00430109
_ZN11gui_objects4font16LaTeXTextHandler20drawStringsIntoImageERNS0_10ImageProxyE
+00000205
[ 4] 0x00007fe828fac92a
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libmwosgserver.so+01759530
_ZN2hg14openscenegraph12TextDrawable4Impl13validateImageEv+00000106
[ 5] 0x00007fe828fac9b4
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libmwosgserver.so+01759668
_ZNK2hg14openscenegraph12TextDrawable18drawImplementationERN3osg10RenderInfoE+
00000068
[ 6] 0x00007fe826dead0f
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01318159
_ZN7osgUtil10RenderLeaf6renderERN3osg10RenderInfoEPS0_+00001375
[ 7] 0x00007fe826de5785
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01296261
_ZN7osgUtil9RenderBin18drawImplementationERN3osg10RenderInfoERPNS_10RenderLeafE+
00000229
[ 8] 0x00007fe826de5814
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01296404
_ZN7osgUtil9RenderBin18drawImplementationERN3osg10RenderInfoERPNS_10RenderLeafE+
00000372
[ 9] 0x00007fe826debf0a
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01322762
_ZN7osgUtil11RenderStage18drawImplementationERN3osg10RenderInfoERPNS_10RenderLea
fE+00000362
[ 10] 0x00007fe826def666
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01336934
_ZN7osgUtil11RenderStage9drawInnerERN3osg10RenderInfoERPNS_10RenderLeafERb+
00000214
[ 11] 0x00007fe826def27a
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01335930
_ZN7osgUtil11RenderStage4drawERN3osg10RenderInfoERPNS_10RenderLeafE+00001146
[ 12] 0x00007fe826deb21b
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01319451
_ZN7osgUtil11RenderStage20drawPostRenderStagesERN3osg10RenderInfoERPNS_10RenderL
eafE+00000059
[ 13] 0x00007fe826def173
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01335667
_ZN7osgUtil11RenderStage4drawERN3osg10RenderInfoERPNS_10RenderLeafE+00000883
[ 14] 0x00007fe826df7d62
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libosgUtil.so.80+01371490
_ZN7osgUtil9SceneView4drawEv+00000450
[ 15] 0x00007fe828fe5454
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libmwosgserver.so+01991764
_ZN2hg14openscenegraph14OsgSceneServer11cullAndDrawEib+00003428
[ 16] 0x00007fe874b992f4
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libuij.so+00197364
_Z23UIJ_call_OpenGLPaintFcnPN11gui_objects12scene_server16SceneServerProxyEib+
00000020
[ 17] 0x00007fe846b9ed0e
/home/esanchez/Software/MATLAB_R2015a/bin/glnxa64/libnativehg.so+00040206
Java_com_mathworks_hg_peer_JavaSceneServerPeer_doDisplay+00000030
[ 18] 0x00007fe8c8bdfe98
<unknown-module>+00000000
[ 19] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 20] 0x00007fe8c8bd18dc
<unknown-module>+00000000
[ 21] 0x00007fe8c8bd18dc
<unknown-module>+00000000
[ 22] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 23] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 24] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 25] 0x00007fe8c8bd18dc
<unknown-module>+00000000
[ 26] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 27] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 28] 0x00007fe8c8bd18dc
<unknown-module>+00000000
[ 29] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 30] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 31] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 32] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 33] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 34] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 35] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 36] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 37] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 38] 0x00007fe8c8bd1468
<unknown-module>+00000000
[ 39] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 40] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 41] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 42] 0x00007fe8c8bd134b
<unknown-module>+00000000
[ 43] 0x00007fe8c8bcb4e7
<unknown-module>+00000000
[ 44] 0x00007fe8da3e7059
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06209625
[ 45] 0x00007fe8da3e6b48
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06208328
[ 46] 0x00007fe8da4255f3
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06465011
JVM_DoPrivileged+00000579
[ 47] 0x00007fe8c8bdfe98
<unknown-module>+00000000
[ 48] 0x00007fe8c8bd134b
<unknown-module>+00000000
[ 49] 0x00007fe8c8bd1ab7
<unknown-module>+00000000
[ 50] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 51] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 52] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 53] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 54] 0x00007fe8c8bd18dc
<unknown-module>+00000000
[ 55] 0x00007fe8c8bd18dc
<unknown-module>+00000000
[ 56] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 57] 0x00007fe8c8bd1170
<unknown-module>+00000000
[ 58] 0x00007fe8c8bd134b
<unknown-module>+00000000
[ 59] 0x00007fe8c8bcb4e7
<unknown-module>+00000000
[ 60] 0x00007fe8da3e7059
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06209625
[ 61] 0x00007fe8da3e6b48
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06208328
[ 62] 0x00007fe8da4255f3
/usr/lib64/jvm/jre-1.7.0-openjdk//lib/amd64/server/libjvm.so+06465011
JVM_DoPrivileged+00000579
[ 63] 0x00007fe8c8bdfe98
<unknown-module>+00000000
[ 64] 0x00007fe8c925a148
<unknown-module>+00000000
If this problem is reproducible, please submit a Service Request via:
http://www.mathworks.com/support/contact_us/
A technical support engineer might contact you with further information.
Thank you for your help.
Using https://es.mathworks.com/help/matlab/ref/saveas.html did not work either.
Have you tried change the PaperPosition via FigHandle.paperPosition=[ ]; Within the brackets you specify the position and size just like you do in your first line. However the units are in inch!

Iniciar sesión para comentar.

 Respuesta aceptada

I had tried: FigHandle.PaperPosition=[100,100,1920,700 ]; --- Seg faulted.
However, I tried this following Looky's advise:
fig = gcf;
fig.PaperPositionMode = 'auto';
print(gcf, [plot_folder,'modelXZ'], '-dpng');
Solved the problem.

1 comentario

Great. Just a little note. Like I said, PaperPosition is in inch (not in Pixel). That's why you got this nasty segmentation fault.
Have a good one

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Debugging and Improving Code en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 16 de Oct. de 2017

Comentada:

el 16 de Oct. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by