Creating a Fill Plot in MATLAB

Plotting: A Filled Triangle

figure(1);
x=[0,3^(1/2),3^(1/2),0];
y=[0,0,1,0];
fill(x,y,'r',…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);

Using a ColorMap

figure(2);
x=[0,3^(1/2),3^(1/2),0];
y=[0,0,1,0];
C=[1,2,3,1]
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet');

Plotting More Complicated Objects

figure(3);
x=[0,1,2,3,4,5]
y=[1,0,1,0,1,0]
C=[1,2,3,4,5,6]
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet')

figure(4)
x=[0,2,4,1,3,5]
y=[1,1,1,0,0,0]
C=[1,2,3,4,5,6]
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet')

figure(5)
x=[0,2,4,1,3,5]
y=[1,1,1,0,0,0]
C=[4,5,6,1,2,3]
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet')

figure(6)
x=[0,2,4,1,3,5]
y=[1,1,1,0,0,0]
C=[2,4,6,1,3,5]
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet')

figure(7)
x=[1:100]';
y=2*x.^3+x+5;
C=y
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet')

figure(8)
x=[1:100]';
y=2*x.^3+x+5;
x=[x;x(end);x(1)];
y=[y;y(1);y(1)];
C=y
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
colormap('jet')

We can also add a colorbar:

figure(9)
x=[1:100]';
y=2*x.^3+x+5;
x=[x;x(end);x(1)];
y=[y;y(1);y(1)];
C=y
fill(x,y,C,…,
'LineWidth',3,…
'EdgeColor','b',…
'FaceAlpha',0.5,…
'EdgeAlpha',0.4);
cmap='jet';
colormap(cmap);
text(10,2e6,cmap,'FontSize',48);
colorbar;

We can apply the other colormaps to this figure:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.