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. Oracle数据库用户介绍

    Oracle数据库创建的时候,创建了一系列默认的用户,有时候可能我们不小心忘记创建了某个用户,比如SCOTT用户,我们就需要使用Oracle提供的脚本来创建,介绍如下: 1.SYS/change_on ...

  2. String.indexOf()的使用方法

    String.indexOf()的用途: 返回此字符串中第一个出现的指定的子字符串,如果没有找到则返回-1 源码如下: /** * Returns the index within this stri ...

  3. Delphi Unicode学习

    String.AnsiString及Tbytes之间的转换一.string转为AnsiString1.直接赋值 (有警告)2.AnsiString()类型强制转换.(无警告) 二.AnsiString ...

  4. CSS-子盒子撑开父盒子,让父盒子的高随内容自适应

    方法一: height:auto!important; height:200px; min-height:200px; ie6并不支持min-height.ie7,opera,火狐没有问题. 方法二: ...

  5. 前端开发HTML&css入门——常用的标签以及一个小练习

    meta标签 <!doctype html> <html> <head> <meta charset="utf-8" /> < ...

  6. linux命令截取文件最后n行(所有命令)

    linux命令截取文件最后n行(所有命令) tail -n a.txt > b.txt 联想:系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) una ...

  7. V7双雄-基于Virtex7XC7VX690T的高性能计算板卡解决方案

    北京太速V7双雄-基于Virtex7XC7VX690T的高性能计算板卡

  8. 脚本_查找 Linux 系统中的僵尸进程

    #!bin/bash#功能:查找Linux系统中的僵尸进程#作者:liusingbon#使用awk判断ps命令输出的第8列为Z时,显示该进程的 PID 和进程命令ps aux |awk '{if($8 ...

  9. Java中数组在内存中的存放原理?

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/yangyong0717/article/details/79165685Java中数组被实现为对象, ...

  10. 随笔3 HashMap<K,V>

    equals.hashcode和==的区别 在介绍HashMap之前,我想先阐述一下我对这三者的理解,equals这个方法呢,就是在判断是否为同一对象(注意,这里的同一对象和相同的内存地址是不同的), ...