您当前的位置: 首页 >  matlab

slandarer

暂无认证

  • 1浏览

    0关注

    248博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

MATLAB | 面积图、饼状图、水平柱状图的斜线填充(阴影填充)

slandarer 发布时间:2022-09-02 01:33:23 ,浏览量:1

在这里插入图片描述 在这里插入图片描述

没想到叭,阴影柱状图仅仅一天就迎来了(1.5.1)版本,已经支持水平柱状图绘制!!同时本人又连夜赶制了另外两款相关的阴影图绘制函数:

来来来,后文马上介绍一下这三款函数。

另:代码开发基于polyshape对象,阴影柱状图绘制函数理论上需要至少R2017b及之后版本才能使用(越新越好)。(polyshape yyds)

区域填充函数

先讲解此函数如何使用,再在此部分最后给出完整代码:

基本使用

设置为角度为pi/3,80根线条进行填充:

t=0:.01:2*pi;
X=cos(t);
Y=sin(t);

plot(X,Y,'LineWidth',2);
hold on;axis equal
shadowFill(X,Y,pi/3,80);

绘制阴影面积图
t=0:.01:2*pi;
y=sin(t); 

plot(t,y,'LineWidth',2);
hold on;axis equal
shadowFill(t,y,pi/4,80);

绘制两函数中间区域

这个就比较复杂了,给个例子:

t=-.1:.01:pi/2;
y1=sin(t).*2;
y2=t.^2;

hold on
plot(t,y1,'LineWidth',2);
plot(t,y2,'LineWidth',2);

diffy=y1-y2;
tpos=find(diffy>=0);
T=[t(tpos(1):tpos(end)),t(tpos(end):-1:tpos(1))];
Y=[y1(tpos(1):tpos(end)),y2(tpos(end):-1:tpos(1))];


shadowFill(T,Y,pi/5,70);

设置填充颜色和格式
t=-.1:.01:pi/2;
y1=sin(t).*2;
y2=t.^2;

hold on
plot(t,y1,'LineWidth',2);
plot(t,y2,'LineWidth',2);

diffy=y1-y2;
tpos=find(diffy>=0);
T=[t(tpos(1):tpos(end)),t(tpos(end):-1:tpos(1))];
Y=[y1(tpos(1):tpos(end)),y2(tpos(end):-1:tpos(1))];


shadowFill(T,Y,pi/5,70,'LineStyle',':','Color',[.2,.2,.9]); 

工具函数完整代码
function SF=shadowFill(X,Y,theta,num,varargin)
% @author : slandarer
% gzh  : slandarer随笔
if theta>pi/2||theta=max(tY))=[];tYY(tYY=max(tY))=[];tYY(tYY=max(tY))=[];tYY(tYY=max(tY))=[];tYY(tYY            
关注
打赏
1664692598
查看更多评论
0.1263s