MATLAB画图颜色渐变「建议收藏」

MATLAB画图颜色渐变「建议收藏」原文(https://wenku.baidu.com/view/bf87a9d5804d2b160a4ec03f.html)1渐变1.1t=[linspace(0,2*pi)nan];x=sin(t);y=cos(2*t);z=sqrt(t);%所要绘制的曲线方程patch(x,y,z,z,’edgecolor’,’flat’,’facecolor’,’none’)vi…

大家好,又见面了,我是你们的朋友全栈君。

原文(https://wenku.baidu.com/view/bf87a9d5804d2b160a4ec03f.html

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

MATLAB画图颜色渐变「建议收藏」

 

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

 

 

MATLAB画图颜色渐变「建议收藏」

1.3 柱状图填色

Matlab绘制彩色柱状图

 http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif (2012-09-28 12:58:34)

http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif转载

标签: 

彩色柱状图

 

杂谈

分类: Matlab

首先,看一下效果图。

默认条件下的柱状图颜色均为蓝色,现在可以绘制漂亮的柱状图以及渐变着色的柱状图。

MATLAB画图颜色渐变「建议收藏」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         1×1                 8  double
%   fvcd      66×1               528  double
%   fvd       13×4               416  double
%   izs       13×1               104  double
%   zs        13×1               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)

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/138265.html原文链接:https://javaforall.net

(1)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号