フィルターのクリア

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

19 ビュー (過去 30 日間)
Eduardo Sanchez
Eduardo Sanchez 2017 年 10 月 16 日
コメント済み: Looky 2017 年 10 月 16 日
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 件のコメント
Eduardo Sanchez
Eduardo Sanchez 2017 年 10 月 16 日
Using https://es.mathworks.com/help/matlab/ref/saveas.html did not work either.
Looky
Looky 2017 年 10 月 16 日
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!

サインインしてコメントする。

採用された回答

Eduardo Sanchez
Eduardo Sanchez 2017 年 10 月 16 日
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 件のコメント
Looky
Looky 2017 年 10 月 16 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by