# 【MATLAB】关于曲线之间颜色填充以及填充色透明度的问题

matlab中有多种填充曲线之间空间颜色的方法，在此介绍几种常用颜色填充方法

1. fill命令

fill命令填充曲线的颜色的引用格式：

x = 0:0.01:2*pi;

y = sin(x);

fill([x,fliplr(x)],[y,0*ones(1,length(y))],'r')

x = 0:0.01:2*pi;

y = sin(x);

h = fill([x,fliplr(x)],[y,0*ones(1,length(y))],'r');

set(h,'edgealpha',0,'facealpha',0.3)

close all;figure

[xx,yy] = meshgrid(1:10,1:10);

fill3([xx(1,:) fliplr(xx(1,:))],[yy(1,:) yy(end,:)],0*ones(1,2*length(yy(1,:))),'r')

grid on;

hold on;

fill3([xx(:,1);flipud(xx(:,end))],[yy(:,1);flipud(yy(:,end))],1*ones(1,2*length(yy(:,end))),'g')

h = fill3([xx(:,1);flipud(xx(:,end))],[yy(:,1);flipud(yy(:,end))],-1*ones(1,2*length(yy(:,end))),'b');

set(h,'edgealpha',0,'facealpha',0.3)

zlim([-2 2])

2. patch命令

patch命令引用格式与fill类似

close all;figure

x = 0:0.01:2*pi;

y = sin(x);

patch([x,fliplr(x)],[y,0*ones(1,length(y))],'r')

close all;figure

x = 0:0.01:2*pi;

y = sin(x);

h = patch([x,fliplr(x)],[y,0*ones(1,length(y))],'r')；

set(h,'edgealpha',0,'facealpha',0.3)

close all;figure

[xx,yy] = meshgrid(1:10,1:10);

patch([xx(1,:) fliplr(xx(1,:))],[yy(1,:) yy(1,:)],[-1*ones(1,length(yy(1,:))) 1*ones(1,length(yy(1,:)))],'r')

grid on;

hold on;

patch([xx(1,:) fliplr(xx(1,:))],[yy(2,:) yy(2,:)],[-1*ones(1,length(yy(1,:))) 1*ones(1,length(yy(1,:)))],'g')

h = patch([xx(:,1);xx(:,1)],[yy(:,1);flipud(yy(:,end))],[-1*ones(1,length(yy(1,:)))... 1*ones(1,length(yy(1,:)))],'b');

set(h,'edgealpha',0,'facealpha',0.3)

zlim([-2 2])

https://m.sciencenet.cn/blog-2824237-1134014.html

## 全部精选博文导读

GMT+8, 2024-5-25 01:15