Using the print command makes disappearing a surface from a figure

조회 수: 3 (최근 30일)
mortain
mortain 2015년 9월 4일
댓글: mortain 2015년 9월 14일
Hello,
I am using Matlab R2014b. I have a picture which is made by 3 items: 1) lines made with plot 2) cloud of points made by stem 3) surface made using surf
figure
plot(t,wg,'b')
hold on
stem3(D(:,1),D(:,2),zeros(N,1),'b.');
s1 = surf(XX,YY,PPDF2,'EdgeColor','none','LineStyle','none');
shading flat;alpha(s1,'color');
sub1=gca;
view(2)
saveas(gcf,[city'.fig'])
print('-dpng','-r600',[city,'.png'])
When I do the print command, the surface disappears. I googled and it seems to be related to the alpha .... I like the way the plot looks and I would like to export it at high res as png. I tried epsc and I get the same problem.
If you give me your email address, I will send you the fig image. Any suggestion is welcome :-)
Thanks a lot
Antonio

채택된 답변

Matt Cohen
Matt Cohen 2015년 9월 8일

Hi Mortain,

I understand that you are encountering an issue where a surface does not appear in a PNG image when using the print command in MATLAB R2014b.

Since you did not provide the specific data used to create the figure in the code snippet, I created some dummy variables to try to reproduce the issue. The code I used is shown below:

N = 15;
t = linspace(0,1,N);
wg = linspace(0,1,N);
D = rand(N,2);
XX = rand(N);
YY = rand(N);
PPDF2 = rand(N);
city = 'boston';
figure
plot(t,wg,'b')
hold on
stem3(D(:,1),D(:,2),zeros(N,1),'b.');
s1 = surf(XX,YY,PPDF2,'EdgeColor','none','LineStyle','none');
shading flat;alpha(s1,'color');
sub1=gca;
view(2)
saveas(gcf,[city '.fig'])
print('-dpng','-r600',[city,'.png'])

I have also included the PNG output from the code snippet above:

The example code does not produce the same issue that you are experiencing. In the image, you can see the line running diagonally across the figure, the surface with the specified transparency visible throughout the figure, and various points from the stem plot on the right side of the figure.

This issue might be related to the renderer being used. The two renderer options are OpenGL and Painters. Each renderer displays and sorts objects in different ways. To check the current renderer, you can use the command "get(gcf,'renderer')" while the figure is open. It is likely using OpenGL for this. You could try setting the renderer to Painters ("set(gcf,'renderer','painters')") or including the '-painters' flag in the "print" command. Additionally, you could try entering the command "opengl software" before running the code and seeing if this possibly changes the output. To help further, though, I would need to be able to work with your figure. You can attach a .fig file to a question or comment in MATLAB Answers.

If none of this helps resolve your issue, you could consider using the function "export_fig", which can be found at the following link:

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

Note that this is a MATLAB File Exchange submission from a user, so it is not directly supported by MathWorks. However, it is a popular tool for exporting figures and has proven to be successful in creating a wide variety of exported images and files.

I hope this helps.

Matt Cohen

  댓글 수: 1
mortain
mortain 2015년 9월 14일
Thanks Matt for your reply. I actually achieved this by using export_fig. Then, another day, I wrote a script where I opened the figure and instead of grabbing the last figure with gcf I just used the print command, and actually the png came out ok.
Thanks again Antonio

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 9월 8일
print('-opengl', '-dpng','-r600',[city,'.png'])
  댓글 수: 1
mortain
mortain 2015년 9월 14일
Thanks a lot for your reply Walter. I tried changing the driver and didn't work. I found another solution as explained above :-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by