MATLAB: How to move and rescale a pie chart drawn over another graphic

chart;MATLABmovepiescale

I would like to move and rescale a pie chart that I have plotted on top of another graphic object.

Best Answer

The ability to move and rescale a pie chart is not available in MATLAB.
To work around the issue, move and rescale the patch graphics and text labels individually.
PIE does not produce a single handle for the entire plot; instead, it produces a collection of PATCH graphics to represent the slices, and a series of text labels. The most direct way to move the pie is to directly modify the position and size of the individual slices and labels. This segment of code walks through the resulting list, scaling and moving pie slices (represented as patch graphics) and text:
contour(membrane(1));
axis square;
hold on;
X = [1 3 5];
h = pie(X);
%Move to xpos,ypos and rescale by scale
xpos = 10;
ypos = 22;
scale = 5;
for k = 1:length(h) % Walk the vector of text and patch handles
if strcmp(get(h(k),'Type'),'patch') % Patch graphics
XData = get(h(k),'XData'); % Extract current data
YData = get(h(k),'YData');
set(h(k),'XData',XData*scale + xpos); % Insert modified data
set(h(k),'YData',YData*scale + ypos);
else % Text labels
Pos = get(h(k),'Position'); % Extract
set(h(k),'Position',Pos*scale + [xpos ypos 0]); % Insert
set(h(k),'FontSize',8);
end
end