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的更多相关文章

  1. histogram 和 bar plot的区别

    最本质的区别是这样的:histogram用来描述的是numerical变量,而bar plot用来描述的是categorical类型的变量.统计学当中关于变量的分类 这可以从它们的图形上面看到: hi ...

  2. 基于matplotlib的数据可视化 - 柱状图bar

    柱状图bar 柱状图常用表现形式为: plt.bar(水平坐标数组,高度数组,宽度比例,ec=勾边色,c=填充色,label=图例标签) 注:当高度值为负数时,柱形向下 1 语法 bar(*args, ...

  3. Java基础之扩展GUI——添加状态栏(Sketcher 1 with a status bar)

    控制台程序. 为了显示各个应用程序参数的状态,并且将各个参数显示在各自的面板中,在应用程序窗口的底部添加状态栏是常见且非常方便的方式. 定义状态栏时没有Swing类可用,所以必须自己建立StatusB ...

  4. 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 ...

  5. Android设计和开发系列第二篇:Action Bar(Develop—Training)

    Adding the Action Bar GET STARTED DEPENDENCIES AND PREREQUISITES Android 2.1 or higher YOU SHOULD AL ...

  6. 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 ...

  7. 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 ...

  8. Pandas:plot相关函数

    0.注意事项 及 各种错误 1)绘制bar图时,如果出现重复的x值被合并到一个情况(导致X轴应该显示内容有缺失),可能是由于Pandas版本太低: 2)无法设置中文title,在代码中加入两句话: p ...

  9. 共用y轴的双图形绘制

    实现这种形式的图形,可通过matplotlib和pandas的实现,相比下pandas实现方便的多. 我数据分析的时候主要是stacked bar.bar和line形式的放在一张图上.stacked ...

随机推荐

  1. php7.3连接MySQL8.0报错 PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]

    报的错误: In Connection.php line : SQLSTATE[HY000] [] The server requested authentication method unknown ...

  2. Mac入门--Apache/Php/Mysql的开启关闭

    注意:mac自带apache环境和PHP环境 一 php服务的启动和关闭 php-fpm 启动 sudo php-fpm php-fpm 关闭 1 查看php-fpm端口是否在被php-fpm进程 n ...

  3. Java相关面试题总结+答案(七)

    [Hibernate] 113. 为什么要使用 hibernate? hibernate 是对 jdbc 的封装,大大简化了数据访问层的繁琐的重复性代码. hibernate 是一个优秀的 ORM 实 ...

  4. SpringBoot 参数检查 Controller中检查参数是否合法

    springboot 验证 默认使用的是hibernate validator ,不用额外增加引用包,springboot已经内置包含. 设置pom相关依赖 <?xml version=&quo ...

  5. JDK11 | 第五篇 : 启动单个Java源代码文件的程序

    文章首发于公众号<程序员果果> 地址 : https://mp.weixin.qq.com/s/h1L4FmzVSix434gVt8Fc7w 一.简介 JEP330-启动单文件代码程序(L ...

  6. 旧接口注册LED字符驱动设备(静态映射)

    #include <linux/init.h> // __init __exit #include <linux/module.h> // module_init module ...

  7. 前端:let与var的区别

    详细情况可跳转到下面这个链接阅读: https://www.cnblogs.com/yukixing/p/11523259.html [收集别人总结好的知识点,也是高效学习的一种方式!]

  8. 5.MCScanX 与circos下载、安装、运用

    一.MCSCAN 参考 :http://chibba.pgml.uga.edu/mcscan2/MCScanX.zip   http://chibba.pgml.uga.edu/mcscan2/#tm ...

  9. CentOS7搭建Docker镜像实战

    开发十年,就只剩下这套架构体系了! >>>   一.搭建环境 使用的是VMWare 12虚拟机安装的CentOS7 安装成功后修改ip: 1. ip addr查看相关信息: 2. 修 ...

  10. express快速入门

    1.简介: express是基于Node.js平台,快速开放极简的web开发框架,使用 各种http使用工具和中间件,创建强大API. 2.安装 npm install express -g 全局安装 ...