3D Pie Plots in MATLAB®

How to make 3D Pie Plots in MATLAB® with Plotly.


Create 3-D Pie Chart

Create a 3-D pie chart of vector x.

x = [1,3,0.5,2.5,2];
figure
pie3(x)

fig2plotly(gcf, 'TreatAs', 'pie3');

To offset the second pie slice, set the corresponding explode element to 1.

x = [1,3,0.5,2.5,2];
figure
pie3(x)

explode = [0,1,0,0,0];
figure
pie3(x,explode)

fig2plotly(gcf, 'TreatAs', 'pie3');

Specify Text Labels for 3-D Pie Chart

Create a 3-D pie chart and specify the text labels.

x = 1:3;
labels = {'Taxes','Expenses','Profit'};

figure
pie3(x,labels)

fig2plotly(gcf, 'TreatAs', 'pie3');

Compare Two Pie Charts

Create vectors y2010 and y2011, that contain financial data for two years. Then create a cell array containing the labels for the values.

y2010 = [50 0 100 95];
y2011 = [65 22 97 120];
labels = {'Investments','Cash','Operations','Sales'};

Create a 2-by-1 tiled chart layout, and display a pie chart and legend for y2010 data in the first tile. Then display a pie chart and legend for the y2011 data in the second tile.

y2010 = [50 0 100 95];
y2011 = [65 22 97 120];
labels = {'Investments','Cash','Operations','Sales'};

t = tiledlayout (2,1);
ax1 = nexttile;
pie3(ax1,y2010);
title('2010');
legend(labels);

ax2 = nexttile;
pie3(ax2,y2011);
title('2011');
legend(labels);

fig2plotly(gcf, 'TreatAs', 'pie3');