尝试在Matlab中将renderer
设置为painters
时,我遇到了一种特别奇怪的行为。在绘制图形之后,如果图形首先在屏幕上从其初始位置移动,则命令set(gcf,'renderer','painters')
仅能正确执行。如果在执行所述命令之前未移动该图形,则会在命令窗口中显示以下错误消息:
java.lang.IllegalArgumentException: adding a container to a container on a different GraphicsDevice
at java.awt.Component.checkGD(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at com.mathworks.hg.peer.FigurePanel.assembleFigurePanel(FigurePanel.java:218)
at com.mathworks.hg.peer.FigurePanel.reconstructFigurePanel(FigurePanel.java:143)
at com.mathworks.hg.peer.FigurePanel.handleNotification(FigurePanel.java:88)
at com.mathworks.hg.peer.FigureNotificationHandlerImpl.forwardNotification(FigureNotificationHandlerImpl.java:62)
at com.mathworks.hg.peer.FigureNotificationHandlerImpl.handleNotification(FigureNotificationHandlerImpl.java:29)
at com.mathworks.hg.peer.FigureAxisComponentProxy.construct(FigureAxisComponentProxy.java:89)
at com.mathworks.hg.peer.FigureAxisComponentProxy.setVisual(FigureAxisComponentProxy.java:112)
at com.mathworks.hg.peer.FigureHG1Mediator.setClientVisual(FigureHG1Mediator.java:135)
at com.mathworks.hg.peer.FigurePeer.doSetVisual(FigurePeer.java:2418)
at com.mathworks.hg.peer.FigurePeer.access$1100(FigurePeer.java:119)
at com.mathworks.hg.peer.FigurePeer$25.run(FigurePeer.java:2430)
at com.mathworks.hg.util.HGPeerQueue$HGPeerRunnablesRunner.runit(HGPeerQueue.java:228)
at com.mathworks.hg.util.HGPeerQueue$HGPeerRunnablesRunner.runNotThese(HGPeerQueue.java:260)
at com.mathworks.hg.util.HGPeerQueue$HGPeerRunnablesRunner.run(HGPeerQueue.java:276)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
如果我只打印一个图,我不介意默认这个Matlab的特性,但我想生成图并通过循环语句迭代地保存eps / pdf输出。如何避免这种特殊要求?
我构建了一个最小的工作示例,可以帮助诊断问题。
x=1:10;
y1=1:10;
y2=11:20;
ax1=axes;
[ax,Y1,Y2]=plotyy(x,y1',x,y2',@bar,@bar);
patchY2 = get(Y2,'children');
set(patchY2,'FaceAlpha',0.65);
ax2=axes('Position',[0 -10 1 1]);
linkaxes([ax ax2],'x');
rgb2cm
set(gcf,'renderer','painters');
请注意,rgb2cm
是对MATLAB文件交换的提交。它的作用是用colormap
- 索引颜色替换补丁rgb颜色,以便renderer
可以设置为painters
。
编辑:在带有3.2.0-4-amd64内核的Debian 7计算机上使用MATLAB 7.11.0(R2010b)会出现问题。
答案 0 :(得分:0)
首先打开并移动图形,然后为循环中的每个图重复使用相同的图形,使用clf
在保存后清除图形。