matlab图像固定区域,matlab – 根据条件颜色指定图形背景区域

这篇博客展示了如何在Matlab中创建条形图,并为条形图添加背景颜色,使得背景条形图比前景条形图高一个单位,从而形成层次感。通过定义参数设置颜色和宽度,博主详细解释了绘制过程,包括先绘制背景条形图,然后用'hold on'保持图形,再绘制前景黑色条形图,最后添加坐标轴标签。
摘要由CSDN通过智能技术生成

是的,这是可能的

%# define some parameters

backgroundColor = 'r';

backgroundWidth = 0.9;

foregroundWidth = 0.3;

%# collect the data

graph = [2 3 5 4 9 1 7];

color = [0 2 2 1 0 1 2];

x = 0:length(graph)-1;

colIdx = color>1;

bgBarHeight = max(graph)+1; %# background bars are 1 taller than max

%# first, plot red bars - I plot them as background as in your question,

%# not as transparent overlay as in your example (see yuk's answer for that)

bar(x,colIdx*bgBarHeight,backgroundWidth,'FaceColor',backgroundColor,'EdgeColor','none')

%# use hold on to prevent background from disappearing

hold on

%# then, plot foreground bars. Use hold on so that the background isn't lost

bar(x,graph,foregroundWidth,'FaceColor','k')

%# label the axes

xlabel('X Axis')

ylabel('Y Axis')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值