Plot 使用-nodisplay-nodesktop-nosplash打印Matlab图形

Plot 使用-nodisplay-nodesktop-nosplash打印Matlab图形,plot,maps,matlab,matlab-figure,Plot,Maps,Matlab,Matlab Figure,我正在使用Matlab的映射工具箱创建并打印一个北美的圆锥形投影图。当我在IDE中运行代码时,绘图被正确打印和保存,但是当在命令行上使用-nodisplay-nodesktop-nosplash运行相同的脚本时,我遇到了一个非常奇怪的问题 在print()函数调用期间,Matlab停止运行脚本,不会出现任何错误、警告或崩溃日志。Matlab实际上并没有崩溃…它只是停止执行我的代码。假定可以在不显示的情况下打印图形 其他人也遇到过类似的问题,并在网上询问过 到目前为止,还没有人提出解决方案。有人

我正在使用Matlab的映射工具箱创建并打印一个北美的圆锥形投影图。当我在IDE中运行代码时,绘图被正确打印和保存,但是当在命令行上使用-nodisplay-nodesktop-nosplash运行相同的脚本时,我遇到了一个非常奇怪的问题

在print()函数调用期间,Matlab停止运行脚本,不会出现任何错误、警告或崩溃日志。Matlab实际上并没有崩溃…它只是停止执行我的代码。假定可以在不显示的情况下打印图形

其他人也遇到过类似的问题,并在网上询问过

到目前为止,还没有人提出解决方案。有人有什么建议吗?提前谢谢

编辑1:

下面是一些自我包含的代码来重现这个问题。我已经在R2011b和R2012a上进行了测试

figure(1)
axesm eckert4; framem; gridm; axis off; tightmap

load geoid
contourfm(geoid, geoidrefvec, -120:20:100, 'LineStyle', 'none');

coast = load('coast');
geoshow(coast.lat, coast.long, 'Color', 'black')

contourcbar

print('-f1','-dpng','-r200','-painters', 'example');

我得出的结论是,这个问题是无法解决的,是一个bug

我最接近解决问题的方法是使用shell中的以下代码:

$ matlab -nosplash -nodisplay < makefigure.m
将输出1200x900像素的png文件“myfig.png”。不幸的是,虽然图像是我想要的大小,但图形本身仍然很小。我不确定这是什么原因,但我相信这与以下事实有关:Matlab是面向对象的,轴应该与图形大小相关联(这就是gca的“位置”变量的标准化)。无论出于何种原因,当显示器关闭时都不会发生这种情况。我怀疑Mathwoks会很快解决这个问题,我不能责怪他们,因为绝大多数Matlab用户都使用GUI

可以帮助任何人解决此问题的一个潜在线索是,在命令行上运行时会出现错误:

Warning: Objects of graph2d.lineseries class exist - not clearing this class
or any of its super-classes 
我寻找了一个解决方案,但发现了更多的问题。我的怀疑是,如果有人能弄明白这意味着什么,你就可以解决这个问题。现在,我将再次回到python,因为使用Matlab,我只需花费数小时处理不便之处,而不是提高效率

编辑: 如果有帮助,这是Matlab2012a
Linux。。。2.6.35.6-45.fc14.x86#u 64#1 SMP。。。x86_64 x86_64 x86_64 GNU/Linux

如果使用脚本运行MATLAB,则会出现以下警告,例如

#!/bin/sh
nohup matlab -nodisplay -nodesktop -r myCode > myLog.log &
exit  


问题是matlab代码希望显示图形、绘图或其他内容,但选项
-nodisplay
禁止它。我解决了这个问题,只需在我的代码
set(gcf,'visible','off')中添加以下行并在末尾
关闭gcf;清除gcf。现在,绘图图例与第一个没有移位的绘图一样,我没有收到任何警告。

在我们尝试回答您的问题之前,您可以发布一个,而不是要求我们下载源代码的zip文件吗。另外,链接到代码通常是一个坏主意,因为如果链接被破坏(比如你停止使用dropbox),那么这个问题可能是非常无用的。我明白了。不幸的是,我正在制作的绘图是一个大得多的软件包的一部分,但我将尝试编写一些自包含的代码来复制它。@GPSmaster:我假设您使用的是Linux机器。我在WinXP上导出MatlabR2012a中的图形没有问题(尽管它警告您不要使用painters渲染器)。是的,我使用的是linux。我已经在REHL5和ubuntu 10.10上试用过了。为了澄清,您使用-nodisplay-nodesktop和-nosplash选项从命令行运行了代码?因为如果我在IDE中运行相同的代码,我也可以导出图形。@GPSmaster:是的。我将您的代码保存为
myscript.m
,然后运行:
matlab-nodesktop-noFigureWindows-nosplash-r“myscript;quit”
noFigureWindows
是仅Unix的Windows等价物
nodisplay
选项)
#!/bin/sh
nohup matlab -nodisplay -nodesktop -r myCode > myLog.log &
exit  
[Warning: Objects of graph2d.lineseries class exist - not clearing this class or
any of its superclasses] 
[Warning: Objects of scribe.legend class exist - not clearing this class or any
of its superclasses] 
[Warning: Objects of graphics.panbehavior class exist - not clearing this class
or any of its superclasses] 
[Warning: Objects of graphics.zoombehavior class exist - not clearing this class
or any of its superclasses] 
[Warning: Objects of graphics.rotate3dbehavior class exist - not clearing this
class or any of its superclasses] 
[Warning: Objects of graphics.datacursorbehavior class exist - not clearing this
class or any of its superclasses] 
[Warning: Objects of graphics.ploteditbehavior class exist - not clearing this
class or any of its superclasses]