Matlab绘制彩色渐变色柱状图
2013-03-25 20:34
671 查看
转自:http://blog.sina.com.cn/s/blog_5fe5061101013lhq.html
% 彩色柱状图
%% 用到的数据
n = 13;
Z = rand(n,1);
%% 默认图片
bar(Z);
%% 简单的作图
% 这个图根据数据列中值的大小着色。每列中的
% 值越大,颜色越突出
figure
h=bar(Z);
colormap(summer(n));
ch = get(h,'Children');
fvd = get(ch,'Faces');
fvcd = get(ch,'FaceVertexCData');
[~, izs] = sortrows(Z,1);
for i = 1:n
row = izs(i);
fvcd(fvd(row,:)) = i;
end
set(ch,'FaceVertexCData',fvcd)
%% 更加漂亮的图片
% 图片会以渐变的方式着色,效果非常不错
figure
h=bar(Z);
ch = get(h,'Children');
fvd = get(ch,'Faces');
fvcd = get(ch,'FaceVertexCData');
[zs, izs] = sortrows(Z,1);
k = 128; % 准备生成128 *3 行的colormap
colormap(summer(k));
% 这样会产生一个128 * 3的矩阵,分别代表[R G B]的值
% 检视数据
whos ch fvd fvcd zs izs
%
% Name Size Bytes Class Attributes
%
% ch 1x1 8 double
% fvcd 66x1 528 double
% fvd 13x4 416 double
% izs 13x1 104 double
% zs 13x1 104 double
%
shading interp % Needed to graduate colors
for i = 1:n
color = floor(k*i/n);
% 这里用取整函数获得color在colormap中行
row = izs(i); % Look up actual row # in data
fvcd(fvd(row,1)) =
1; % Color base vertices 1st index
fvcd(fvd(row,4)) =
1;
fvcd(fvd(row,2)) = color;
% Assign top vertices color
fvcd(fvd(row,3)) = color;
end
set(ch,'FaceVertexCData', fvcd);
% Apply the vertex coloring
set(ch,'EdgeColor','k')
% 彩色柱状图
%% 用到的数据
n = 13;
Z = rand(n,1);
%% 默认图片
bar(Z);
%% 简单的作图
% 这个图根据数据列中值的大小着色。每列中的
% 值越大,颜色越突出
figure
h=bar(Z);
colormap(summer(n));
ch = get(h,'Children');
fvd = get(ch,'Faces');
fvcd = get(ch,'FaceVertexCData');
[~, izs] = sortrows(Z,1);
for i = 1:n
row = izs(i);
fvcd(fvd(row,:)) = i;
end
set(ch,'FaceVertexCData',fvcd)
%% 更加漂亮的图片
% 图片会以渐变的方式着色,效果非常不错
figure
h=bar(Z);
ch = get(h,'Children');
fvd = get(ch,'Faces');
fvcd = get(ch,'FaceVertexCData');
[zs, izs] = sortrows(Z,1);
k = 128; % 准备生成128 *3 行的colormap
colormap(summer(k));
% 这样会产生一个128 * 3的矩阵,分别代表[R G B]的值
% 检视数据
whos ch fvd fvcd zs izs
%
% Name Size Bytes Class Attributes
%
% ch 1x1 8 double
% fvcd 66x1 528 double
% fvd 13x4 416 double
% izs 13x1 104 double
% zs 13x1 104 double
%
shading interp % Needed to graduate colors
for i = 1:n
color = floor(k*i/n);
% 这里用取整函数获得color在colormap中行
row = izs(i); % Look up actual row # in data
fvcd(fvd(row,1)) =
1; % Color base vertices 1st index
fvcd(fvd(row,4)) =
1;
fvcd(fvd(row,2)) = color;
% Assign top vertices color
fvcd(fvd(row,3)) = color;
end
set(ch,'FaceVertexCData', fvcd);
% Apply the vertex coloring
set(ch,'EdgeColor','k')
相关文章推荐
- 利用MATLAB绘制三维彩色柱状图
- MATLAB之pcolor—绘制伪彩色图
- 基于matlab的三维柱状图绘制
- 使用matlab绘制柱状图
- Matlab将系统自动生成的figure 1改为其他名称 & 柱状图绘制
- matlab绘制柱状图
- matlab绘制带有吴茶邦(error)的分组柱状图
- MATLAB绘制双轴倒立降水柱状图
- MATLAB绘制带图案的柱状图
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)
- MATLAB绘制3D隐函数曲面的方法总结
- matlab 彩色图像操作
- Matlab实用代码——直方图的绘制并在单个直方图上标注对应数字
- 双边滤波(bilateral filter)彩色图 matlab实现代码
- 【matlab】利用matlab在图形中绘制箭头、标注、圈圈 - 很帅很酷炫
- matlab 图形绘制 plot
- OpenGL入门示例4——黑色背景绘制彩色点画线
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)
- VS2010 使用TeeChart绘图控件 - 之二 - 绘制图形(折线图,柱状图)
- CorePlot_1.5.1 绘制柱状图