matlab柱状图填充纹理和颜色
时间: 2023-10-31 21:02:41 浏览: 465
在MATLAB中,可以使用`bar`函数绘制柱状图,并使用`hatchfill`函数填充其纹理。以下是一个示例代码:
```matlab
% 创建数据
x = [1 2 3 4 5];
y = [10 5 12 8 3];
% 绘制柱状图
bar(x, y);
% 填充纹理和颜色
hatchfill(bar(x, y), 'single', 45, 5, [0.6 0.6 0.6], 'none');
```
这个例子将会绘制一个简单的柱状图,然后使用`hatchfill`函数在每个柱子上填充一些斜线纹理。`hatchfill`函数的第一个参数是`bar`函数的返回值,`'single'`表示使用单个斜线纹理,`45`表示斜线角度,`5`表示线宽,`[0.6 0.6 0.6]`表示填充颜色为灰色,`'none'`表示不使用边框颜色。
如果要填充不同的纹理或颜色,可以修改`hatchfill`函数的参数。例如,以下代码将使用交叉斜线填充纹理,并使用不同的颜色填充每个柱子:
```matlab
% 创建数据
x = [1 2 3 4 5];
y = [10 5 12 8 3];
% 绘制柱状图
bar(x, y);
% 填充不同的纹理和颜色
hatchfill(bar(x, y), 'cross', -45, 5, [1 0.6 0.6], [0.6 0.6 1]);
```
在这个例子中,我们使用`'cross'`参数表示使用交叉斜线填充纹理,`-45`表示斜线角度为负45度,`[1 0.6 0.6]`表示填充颜色为红色,`[0.6 0.6 1]`表示填充颜色为蓝色。
阅读全文
相关推荐


















