matlab中如何画柱状图,如何在用Matlab画柱状图
画柱状图比较方便的还是Excel,不过作为逼格比较高的我们有必要学习一下如何用Matlab玩转柱状图。
y=[67.84 68.89 71.54 71.67;67.17 69.47 73.41 73.14];
b=bar(y);
grid on;
ch = get(b,’children’);
set(gca,’XTickLabel’,{‘Dataset 1′,’Dataset 2′})
% 不知道为什么会报错,在Matlab2009,2011测试都不行
% set(ch,’FaceVertexCData’,[1 0 0;0 1 0; 0 0 1; 1 0 1]);
legend(‘Fea. 1′,’Fea. 2′,’Fea. 3′,’Fea. 4’);
xlabel(‘Datasets’);
ylabel(‘Precision’);
另一个比较好用的:
>> a=[1 2 3];
>> b=diag(a);
>> c=bar(b,’stack’);
>> color=[0 0 0.75;0 1 0;1 0.5 0];
>> for i=1:3
set(c(i),’FaceColor’,color(i,:));
end
====================但是问题来了,上面方式是以颜色区分不同柱状的,下面我们寻思靠图案来区分的方式==============
主要参考:http://blog.sciencenet.cn/blog-40165-308439.html
http://www.aos.wisc.edu/~dvimont/matlab/Graphics_Tools/applyhatch.html
function applyhatch(h,patterns,colorlist)
%APPLYHATCH Apply hatched patterns to a figure
% APPLYHATCH(H,PATTERNS) creates a new figure from the figure H by
% replacing distinct colors in H with the black and white
% patterns in PATTERNS. The format for PATTERNS can be
% a string of the characters ‘/’, ‘\’, ‘|’, ‘-‘, ‘+’, ‘x’, ‘.’
% a cell array of matrices of zeros (white) and ones (black)
%
% APPLYHATCH(H,PATTERNS,COLORS) maps the colors in the n by 3
% matrix COLORS to PATTERNS. Each row of COLORS specifies an RGB
% color value.
%
% Note this function makes a bitmap image of H and so is limited
% to low-resolution, bitmap output.
%
% Example 1:
% bar(rand(3,4));
% applyhatch(gcf,’\-x.’);
%
% Example 2:
% colormap(cool(6));
% pie(rand(6,1));
% legend(‘Jan’,’Feb’,’Mar’,’Apr’,’May’,’Jun’);
% applyhatch(gcf,’|-+.\/’,cool(6));
%
% See also: MAKEHATCH
% By Ben Hinkle, bhinkle@mathworks.com
% This code is in the public domain.
oldppmode = get(h,’paperpositionmode’);
oldunits = get(h,’units’);
set(h,’paperpositionmode’,’auto’);
set(h,’units’,’pixels’);
figsize = get(h,’position’);
if nargin == 2
colorlist = [];
end
bits = hardcopy(h,’-dzbuffer’,’-r0′);
set(h,’paperpositionmode’,oldppmode);
bwidth = size(bits,2);
bheight = size(bits,1);
bsize = bwidth * bheight;
if ~isempty(colorlist)
colorlist = uint8(255*colorlist);
[colors,colori] = nextnonbw(0,colorlist,bits);
else
colors = (bits(:,:,1) ~= bits(:,:,2)) | …
(bits(:,:,1) ~= bits(:,:,3));
end
pati = 1;
colorind = find(colors);
while ~isempty(colorind)
colorval(1) = bits(colorind(1));
colorval(2) = bits(colorind(1)+bsize);
colorval(3) = bits(colorind(1)+2*bsize);
if iscell(patterns)
pattern = patterns{pati};
elseif isa(patterns,’char’)
pattern = makehatch(patterns(pati));
else
pattern = patterns;
end
pattern = uint8(255*(1-pattern));
pheight = size(pattern,2);
pwidth = size(pattern,1);
ratioh = ceil(bheight/pheight);
ratiow = ceil(bwidth/pwidth);
bigpattern = repmat(pattern,[ratioh ratiow]);
if ratioh*pheight > bheight
bigpattern(bheight+1:end,:) = [];
end
if ratiow*pwidth > bwidth
bigpattern(:,bwidth+1:end) = [];
end
bigpattern = repmat(bigpattern,[1 1 3]);
color = (bits(:,:,1) == colorval(1)) & …
(bits(:,:,2) == colorval(2)) & …
(bits(:,:,3) == colorval(3));
color = repmat(color,[1 1 3]);
bits(color) = bigpattern(color);
if ~isempty(colorlist)
[colors,colori] = nextnonbw(colori,colorlist,bits);
else
colors = (bits(:,:,1) ~= bits(:,:,2)) | …
(bits(:,:,1) ~= bits(:,:,3));
end
colorind = find(colors);
pati = (pati + 1);
if pati > length(patterns)
pati = 1;
end
end
newfig = figure(‘units’,’pixels’,’visible’,’off’);
imaxes = axes(‘parent’,newfig,’units’,’pixels’);
im = image(bits,’parent’,imaxes);
fpos = get(newfig,’position’);
set(newfig,’position’,[fpos(1:2) figsize(3) figsize(4)+1]);
set(imaxes,’position’,[0 0 figsize(3) figsize(4)+1],’visible’,’off’);
set(newfig,’visible’,’on’);
function [colors,out] = nextnonbw(ind,colorlist,bits)
out = ind+1;
colors = [];
while out <= size(colorlist,1)
if isequal(colorlist(out,:),[255 255 255]) | ...
isequal(colorlist(out,:),[0 0 0])
out = out+1;
else
colors = (colorlist(out,1) == bits(:,:,1)) & ...
(colorlist(out,2) == bits(:,:,2)) & ...
(colorlist(out,3) == bits(:,:,3));
return
end
end
而applyhatch函数需要调用下面的函数
function A = makehatch(hatch)
%MAKEHATCH Predefined hatch patterns
% MAKEHATCH(HATCH) returns a matrix with the hatch pattern for HATCH
% according to the following table:
% HATCH pattern
% ------- ---------
% / right-slanted lines
% \ left-slanted lines
% | vertical lines
% - horizontal lines
% + crossing vertical and horizontal lines
% x criss-crossing lines
% . single dots
%
% See also: APPLYHATCH
% By Ben Hinkle, bhinkle@mathworks.com
% This code is in the public domain.
n = 6;
A=zeros(n);
switch (hatch)
case '/'
A = fliplr(eye(n));
case '\'
A = eye(n);
case '|'
A(:,1) = 1;
case '-'
A(1,:) = 1;
case '+'
A(:,1) = 1;
A(1,:) = 1;
case 'x'
A = eye(n) | fliplr(diag(ones(n-1,1),-1));
case '.'
A(1:2,1:2)=1;
otherwise
error(['Undefined hatch pattern "' hatch '".']);
end
matlab中如何画柱状图,如何在用Matlab画柱状图相关推荐
- stem什么意思matlab,matlab中stem函数用法_常见问题解析,matlab
matlab中如何自定义图例_常见问题解析 matlab中自定义图例的方法:首先打开matlab软件:然后点击勾选按钮,新建一个文件并输入代码为"x = 0:pi/50:2*pi;" ...
- 在MATLAB中使用数学符号,在matlab中怎么输入特殊符号 function在MATLAB中怎么用
导航:网站首页 > 在matlab中怎么输入特殊符号 function在MATLAB中怎么用 在matlab中怎么输入特殊符号 function在MATLAB中怎么用 相关问题: 匿名网友: 一 ...
- matlab plot 错误,Matlab中的绘图错误(Plotting Error in Matlab)
Matlab中的绘图错误(Plotting Error in Matlab) 将matlab图打印成PDF时遇到问题. 在研究了几个小时的解决方案之后,我一直无法找到解决方案. 我一直收到相同的错误消 ...
- matlab中的下划线怎么打,在matlab中怎么输入特殊符号~ , 怎么在Matlab中输入特殊符号...
导航:网站首页 > 在matlab中怎么输入特殊符号~ , 怎么在Matlab中输入特殊符号 在matlab中怎么输入特殊符号~ , 怎么在Matlab中输入特殊符号 匿名网友: 一.文档中的T ...
- matlab中circle函数_MATLAB如何用自带函数画圆
朋友们经常遇到已知圆心和半径,不需要保留圆周点坐标,但是想实现MATLAB的圆形绘制的情况.这时候用角度或者散点生成圆周坐标显然不划算,但是MATLAB又没有Circle之类的函数可以用来直接画圆.这 ...
- matlab中希腊字母相除,如何在matlab中输入希腊字母
Matlab的命2113令窗口中是没有办法输出希5261腊字母的,但是4102画图的时候1653可以在图中输出希腊字回母.希腊字母答等特殊字符用 \加拼音 表示,拼音首字母大写表示大写的希腊字母,小 ...
- 如何在matlab中进行非线性规划,约束非线性规划工具-fmincon(matlab)的使用
motivation: 记录一些fmincon使用方法和应对一些问题的解决方法 1.简介: 在MATLAB中,使用函数x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonl ...
- matlab中利用xy求取多项式z,matlab基础练习题
3. 求有理分式()()()()3323230.522521x x x R x x x x ++=+-++的商多项式和余多项式 4. 一元多项式42234p x x x =-+,写出表示p 的MATL ...
- matlab中a2=poly(p2),插值与拟合matlab实现
插值与拟合的Matlab实现 王正盛编写 在科技工程中,除了要进行一定的理论分析外,通过实验.观测数据,做分析.处理也是必不可少的一种途径.由于实验测定实际系统的数据具有一定的代表性,因此在处理时必须 ...
- matlab中任意两边之和大于第三边,MATLAB教程第三章.ppt
<MATLAB教程第三章.ppt>由会员分享,可在线阅读,更多相关<MATLAB教程第三章.ppt(34页珍藏版)>请在人人文库网上搜索. 1.MATLAB程序语言设计, ,第 ...
最新文章
- 如何利用pyecharts绘制炫酷的关系网络图?
- 匹配“汉字tab键数字”的正则
- springboot里面logback使用
- python【力扣LeetCode算法题库】3- 无重复字符的最长子串
- STVD下配置Cosmic编译器
- BUUCTF(pwn)[HarekazeCTF2019]baby_rop
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- 利用 Python / R 对数据集进行「长」「宽」转换
- 一个带关闭按钮的Div窗口,很漂亮
- 括号匹配不一定用栈哦(洛谷P1739题题解,Java语言描述)
- 【转】Update: Android.mk 中的 LOCAL_SRC_FILES, LOCAL_C_INCLUDES
- NHibernate官方文档中文版——批量插入(Batch inserts)
- Eureka Server 开启身份验证与客户端注册
- Sqoop--全量/增量、导入/导出
- 用Python画出奥运五环图 (Python经典编程案例)
- 《求职》第三部分 - 计算机网络篇 - 计算机网络总结
- Blender导出模型规范检查
- Spark宽窄依赖详解
- zsh: command not found: brew
- pacemaker+corosync的一些总结