Using the print command makes disappearing a surface from a figure

2 次查看(过去 30 天)
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 中查找有关 Printing and Saving 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by