Add hatch to bar plot
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
% 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 :
% bar(rand(,));
% applyhatch(gcf,'\-x.');
%
% Example :
% colormap(cool());
% pie(rand(,));
% legend('Jan','Feb','Mar','Apr','May','Jun');
% applyhatch(gcf,'|-+.\/',cool());
%
% 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 ==
colorlist = [];
end
bits = hardcopy(h,'-dzbuffer','-r0');
set(h,'paperpositionmode',oldppmode);
bwidth = size(bits,);
bheight = size(bits,);
bsize = bwidth * bheight;
if ~isempty(colorlist)
colorlist = uint8(*colorlist);
[colors,colori] = nextnonbw(,colorlist,bits);
else
colors = (bits(:,:,) ~= bits(:,:,)) | ...
(bits(:,:,) ~= bits(:,:,));
end
pati = ;
colorind = find(colors);
while ~isempty(colorind)
colorval() = bits(colorind());
colorval() = bits(colorind()+bsize);
colorval() = bits(colorind()+*bsize);
if iscell(patterns)
pattern = patterns{pati};
elseif isa(patterns,'char')
pattern = makehatch(patterns(pati));
else
pattern = patterns;
end
pattern = uint8(*(-pattern));
pheight = size(pattern,);
pwidth = size(pattern,);
ratioh = ceil(bheight/pheight);
ratiow = ceil(bwidth/pwidth);
bigpattern = repmat(pattern,[ratioh ratiow]);
if ratioh*pheight > bheight
bigpattern(bheight+:end,:) = [];
end
if ratiow*pwidth > bwidth
bigpattern(:,bwidth+:end) = [];
end
bigpattern = repmat(bigpattern,[ ]);
color = (bits(:,:,) == colorval()) & ...
(bits(:,:,) == colorval()) & ...
(bits(:,:,) == colorval());
color = repmat(color,[ ]);
bits(color) = bigpattern(color);
if ~isempty(colorlist)
[colors,colori] = nextnonbw(colori,colorlist,bits);
else
colors = (bits(:,:,) ~= bits(:,:,)) | ...
(bits(:,:,) ~= bits(:,:,));
end
colorind = find(colors);
pati = (pati + );
if pati > length(patterns)
pati = ;
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(:) figsize() figsize()+]);
set(imaxes,'position',[ figsize() figsize()+],'visible','off');
set(newfig,'visible','on');
function [colors,out] = nextnonbw(ind,colorlist,bits)
out = ind+;
colors = [];
while out <= size(colorlist,)
if isequal(colorlist(out,:),[ ]) | ...
isequal(colorlist(out,:),[ ])
out = out+;
else
colors = (colorlist(out,) == bits(:,:,)) & ...
(colorlist(out,) == bits(:,:,)) & ...
(colorlist(out,) == bits(:,:,));
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 = ;
A=zeros(n);
switch (hatch)
case '/'
A = fliplr(eye(n));
case '\'
A = eye(n);
case '|'
A(:,) = ;
case '-'
A(,:) = ;
case '+'
A(:,) = ;
A(,:) = ;
case 'x'
A = eye(n) | fliplr(diag(ones(n-,),-));
case '.'
A(:,:)=;
otherwise
error(['Undefined hatch pattern "' hatch '".']);
end %测试的例子命令
% data = [96.3,92.6,71.2;95.7,93.6,83.9;96.8,94.3,78.3;95.8,92.7,80.3]
% bar(data,)
% axis([ 0.0 ])
% legend('方法','exited','Square')
% set(gca,'XTickLabel',{'Img1','Img2','Img3','Img4'})
% applyhatch(gcf,'\.x.')
---恢复内容结束---
Add hatch to bar plot的更多相关文章
- histogram 和 bar plot的区别
		最本质的区别是这样的:histogram用来描述的是numerical变量,而bar plot用来描述的是categorical类型的变量.统计学当中关于变量的分类 这可以从它们的图形上面看到: hi ... 
- 基于matplotlib的数据可视化 - 柱状图bar
		柱状图bar 柱状图常用表现形式为: plt.bar(水平坐标数组,高度数组,宽度比例,ec=勾边色,c=填充色,label=图例标签) 注:当高度值为负数时,柱形向下 1 语法 bar(*args, ... 
- Java基础之扩展GUI——添加状态栏(Sketcher 1 with a status bar)
		控制台程序. 为了显示各个应用程序参数的状态,并且将各个参数显示在各自的面板中,在应用程序窗口的底部添加状态栏是常见且非常方便的方式. 定义状态栏时没有Swing类可用,所以必须自己建立StatusB ... 
- Status Bar in iOS7
		This is a very important change in iOS 7: the status bar is no longer a separate bar. It’s now somet ... 
- Android设计和开发系列第二篇:Action Bar(Develop—Training)
		Adding the Action Bar GET STARTED DEPENDENCIES AND PREREQUISITES Android 2.1 or higher YOU SHOULD AL ... 
- Android设计和开发系列第二篇:Action Bar(Develop—API Guides)
		Action Bar IN THIS DOCUMENT Adding the Action Bar Removing the action bar Using a logo instead of an ... 
- Android官方文档翻译 八 2.1Setting Up the Action Bar
		Setting Up the Action Bar 建立Action Bar This lesson teaches you to 这节课教给你 Support Android 3.0 and Abo ... 
- Pandas:plot相关函数
		0.注意事项 及 各种错误 1)绘制bar图时,如果出现重复的x值被合并到一个情况(导致X轴应该显示内容有缺失),可能是由于Pandas版本太低: 2)无法设置中文title,在代码中加入两句话: p ... 
- 共用y轴的双图形绘制
		实现这种形式的图形,可通过matplotlib和pandas的实现,相比下pandas实现方便的多. 我数据分析的时候主要是stacked bar.bar和line形式的放在一张图上.stacked ... 
随机推荐
- 词频统计小程序-WordCount.exe
			一. 背景  最近顶哥为了完成学历提升学业中的小作业,做了一个词频统计的.exe小程序.因为当时做的时候网上的比较少,因此顶哥决定把自己拙略的作品发出来给需要的人提供一种思路,希望各位看官不要dis ... 
- Java-第N篇推荐的一些学习书籍
			1.推荐的一些学习书籍或者需要掌握的基本知识 book | |---ant | |---maven | |---git(菜鸟教程) | |---Dos shell | |---linux常用的命令.l ... 
- Java数据结构之稀疏数组(Sparse Array)
			1.需求 编写的五子棋程序中,有存盘退出和续上盘的功能.因为该二维数组的很多值是默认值0,因此记录了很多没有意义的数据,为了压缩存储所以采用稀疏数组. 2.基本介绍 当一个数组中大部分元素为0,或者为 ... 
- 对PInvoke函数函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。
			C#引入外部非托管类库时,有时候会出现“对PInvoke函数调用导致堆栈不对称.原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配”的报错. 通常在DllImport标签内加入属性Call ... 
- flume 进阶
			一.flume事务 put事务流程: 1.doPut:将批量数据先写入临时缓冲区putList 2.doCommit:检查Channel内存队列是否足够, (1)达到一定时间没有数据写入到putLis ... 
- webpack打包html里的img图片
			对待css里的图片, 因为已经通过引入css文件到js,打包了,可以正常通过module.rules.test检测到,然后正常打包. 但是对于html里的图片, 这个需要安装一个插件html-with ... 
- 省流量 转:http://www.wtoutiao.com/p/T3b8it.html
			前言:“客户端上传时间戳”的玩法,你玩过么?一起聊聊时间戳的奇技淫巧! 缘起:无线时代,流量敏感.APP在登录后,往往要向服务器同步非常多的数据,很费流量,技术上有没有节省流量的方法呢?这是本文要讨论 ... 
- R语言抽样的问题
			基本抽样函数sample sample(x,size,replace=F/T) x是数据集, size规定了从对象中抽出多少个数 replace 为F时候,表示每次抽取后的数就不能在下一次被抽取:T ... 
- nginx多层反代配置变量proxy_set_header
			Nginx多层反代配置变量proxy_set_header过程记录 第一层代理: (1)路径: $ vim /data/soft/nginx/conf/vhost/xixi.conf (2)内容:(注 ... 
- KC705E 增强版 基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡
			KC705E 增强版 基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡 一.板卡概述 本板卡基于Xilinx公司的FPGAXC7K325T-2FF ... 
