2024年6月10日发(作者:杨海逸)
1 渐变
1.1
t=[linspace(0,2*pi) nan];
x=sin(t);y=cos(2*t);z=sqrt(t);%所要绘制的曲线方程
patch(x,y,z,z,'edgecolor','flat','facecolor','none')
view(3);grid on;colorbar
1.2
x=-200:5:200;
y=-200:5:200;
z=-200:5:200;
m=linspace(0,1,length(x));
for i=1:length(x);
plot3(x(i),y(i),z(i),'o','color',[m(i) 0 0])
hold on
end
1.3 柱状图填色
Matlab绘制彩色柱状图
(2012-09-28 12:58:34)
转载
标签:
彩色柱状图
▼
分类:
Matlab
杂谈
首先,看一下效果图。
默认条件下的柱状图颜色均为蓝色,现在可以绘制漂亮的柱状图以及渐变着色的柱状图。
% 彩色柱状图
%% 用到的数据
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')
2 符号/线型/颜色/绘图标记
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram 正五边形
h hexagram 正六边形
grid on 坐标带网格线
axis on 显示坐标轴相关标记
axis square 显示方形的 立体的
length(x)=m
size(x)=(m,n)
mesh surf 绘制三维图(网格图 表面图) meshc 绘制带有等值线的三维网格图
[x,y]=meshgrid(x,y)
hold on 图形保持功能
SUBPLOT(m,n,p) 分子区域绘图
AXIS([XMIN XMAX YMIN YMAX]) 指定坐标轴的范围
x=rand(3,2)
bar3(x) 三维柱状图 barh 横向的
pie 饼状图 pie([2 4 3 5],{'North','South','East','West'})
contour 等值线的绘制
view(az,el)、view([az,el]) 指定方位角和俯仰角的大小
plot(x_a,0,'h','MarkerSize',16)
2024年6月10日发(作者:杨海逸)
1 渐变
1.1
t=[linspace(0,2*pi) nan];
x=sin(t);y=cos(2*t);z=sqrt(t);%所要绘制的曲线方程
patch(x,y,z,z,'edgecolor','flat','facecolor','none')
view(3);grid on;colorbar
1.2
x=-200:5:200;
y=-200:5:200;
z=-200:5:200;
m=linspace(0,1,length(x));
for i=1:length(x);
plot3(x(i),y(i),z(i),'o','color',[m(i) 0 0])
hold on
end
1.3 柱状图填色
Matlab绘制彩色柱状图
(2012-09-28 12:58:34)
转载
标签:
彩色柱状图
▼
分类:
Matlab
杂谈
首先,看一下效果图。
默认条件下的柱状图颜色均为蓝色,现在可以绘制漂亮的柱状图以及渐变着色的柱状图。
% 彩色柱状图
%% 用到的数据
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')
2 符号/线型/颜色/绘图标记
b blue . point - solid
g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)
p pentagram 正五边形
h hexagram 正六边形
grid on 坐标带网格线
axis on 显示坐标轴相关标记
axis square 显示方形的 立体的
length(x)=m
size(x)=(m,n)
mesh surf 绘制三维图(网格图 表面图) meshc 绘制带有等值线的三维网格图
[x,y]=meshgrid(x,y)
hold on 图形保持功能
SUBPLOT(m,n,p) 分子区域绘图
AXIS([XMIN XMAX YMIN YMAX]) 指定坐标轴的范围
x=rand(3,2)
bar3(x) 三维柱状图 barh 横向的
pie 饼状图 pie([2 4 3 5],{'North','South','East','West'})
contour 等值线的绘制
view(az,el)、view([az,el]) 指定方位角和俯仰角的大小
plot(x_a,0,'h','MarkerSize',16)