MATLAB: Patch performance with caxis

caxisgraphicsMATLABpatchperformancer2014bgraphics

Is there any way I can improve the performance of patch objects with respect to changing caxis settings or the figure's colourmap?
I have something like the following setup, with an image overlaid by many patch objects (e.g. 60 patch objects, each with ~1300 faces). The patches are all defined with a single colour as [r g b], not indexed into the current colourmap so they do not change with respect to the colourmap or its scaling.
(Note: this is just an example image I created for testing, not my real data, but it should give the idea – the red octagons are patches here)
I wish to be able to change either the underlying image or the colourmap for that image. I have a setup to do this which just replaces the 'CData' of the existing image object for the former meaning that the overlaid patch objects theoretically do not need to be altered at all.
However, the different base images I have are scaled differently so I have to use a caxis instruction after changing the image. This is annoyingly slow to update the image (when I remove the caxis instruction the image updates close to instantaneously). If I don't have the patches overlaid then the image updates almost immediately so it is clearly the patches that are slowing it down.
So is there some setting on patches that I am missing that is causing them to react to the colourmap changing (via caxis or the whole colourmap changing) or is there nothing I can do about this? I had hoped the fact I am setting the patch colour using true [r g b] colour would mean they would be unaffected by caxis type changes and would not need to be redrawn.

Best Answer

Mike Garrity showed me this example earlier with respect to patch:
>> 2.4814 frames per second
>> 20.6223 frames per second
cla
nfaces = 5000;
nsides = 6;
nframes = 20;
ang = linspace(0,2*pi,nsides+1)
x = repmat(cos(ang)',[1 nfaces]);
y = repmat(sin(ang)',[1 nfaces]);
z = repmat([1:nfaces],[(nsides+1) 1]);
xoff = repmat(randn(1,nfaces),[nsides+1, 1]);
yoff = repmat(randn(1,nfaces),[nsides+1, 1]);
h = patch(x+xoff,y+yoff,z,z);
h.FaceColor = 'flat';
h.EdgeColor = 'none';
xlim([-8 8])
ylim([-8 8])
tic
for i=1:nframes
xoff = repmat(randn(1,nfaces),[nsides+1, 1]) / 10;
yoff = repmat(randn(1,nfaces),[nsides+1, 1]) / 10;
h.Vertices = h.Vertices + [xoff(:), yoff(:), zeros(nfaces*(nsides+1),1)];
drawnow;
end
disp([num2str(nframes/toc) ' frames per second'])
f = h.Faces;
if size(f,2) > 3
f2 = [];
f2 = [f2; f(:,1), f(:,2), f(:,3)];
f2 = [f2; f(:,1), f(:,3), f(:,4)];
f2 = [f2; f(:,1), f(:,4), f(:,5)];
f2 = [f2; f(:,1), f(:,5), f(:,6)];
end
h.Faces = f2;
xlim([-8 8])
ylim([-8 8])
tic
for i=1:nframes
xoff = repmat(randn(1,nfaces),[nsides+1, 1]) / 10;
yoff = repmat(randn(1,nfaces),[nsides+1, 1]) / 10;
h.Vertices = h.Vertices + [xoff(:), yoff(:), zeros(nfaces*(nsides+1),1)];
drawnow;
end
disp([num2str(nframes/toc) ' frames per second'])
By simplifying the patches into triangles, things went faster.