print png figure terminal mode remotely

4 views (last 30 days)
Hello everybody
I am facing a problem in matlab because I am trying to scatter3 plot a great amount of figures. So, I decided to give a try via a unix terminal in a cluster instead of a small computer.
However, if I try
matlab -r -nodesktop "instructions;" &
in which the script instructions.m looks like this:
scatter3(x0,y0,z0, '.');
print ('-dpng', 'name0.png')
scatter3(x1,y1,z1, '.');
print ('-dpng', 'name1.png')
scatter3(x2,y2,z2, '.');
print ('-dpng', 'name2.png')
.
etc up to 10000
.
Then, the png are never created because the print function takes a great deal of time making it unefficient.
I have read to try hgsave or saveas but that didn't work either.
I know that if I ssh log in with x11 active then it works but I need to do it without the x11 active.
Could someone please bring me some light in this?
Thank you in advance.

Answers (1)

Surya Talluri
Surya Talluri on 7 Aug 2020
I understand that you are trying to display every scatter plot and then print it.
You can tun off figure visibility and then save the figure. In this way as you are not trying to show any plot GUI, there is no need to enable X11 forwarding and you can directly save the plot.
f = figure('visible','off');
scatter3(x0,y0,z0, '.');
saveas(f,'name0.png')
f = figure('visible','off');
scatter3(x1,y1,z1, '.');
saveas(f,'name1.png')
  1 Comment
Walter Roberson
Walter Roberson on 7 Aug 2020
That figure() command needs to make the figure visible momentarily and then sets it to not visible. Whether you observe a flash or not as the window appears and disappears depends on your system, and the timing, and your window manager.
There are some internal calculations and settings that are postponed until the figure is made visible. If there is any internal call to trigger those calculations and settings without making the figure visible, then I have not been able to find it.
For example the Extent property of a uicontrol is garbage until the control is rendered by the figure being made visible. (You need the Extent to be valid if you are trying to find out the size that some text renders as because you are trying to dynamically size a control to just large enough to include the text. The size cannot be easily computed because it depends on the display resolution and on the font and the content of the text, remembering proportional fonts and kerning.) The only way to get some information is to set the figure visible to trigger the size calculations, then set the figure invisible again. Most of the time you will not see the flash at all, but sometimes you do...

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!