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

效果图:

来自:http://blog.sciencenet.cn/home.php?mod=space&uid=40165&do=blog&id=308439

matlab 画不同图案的柱状图的更多相关文章

  1. MATLAB 画柱状图(/直方图)修改横坐标名称并使其横着显示

    使用MATLAB 画柱状图 ,即bar (x,y),其横坐标是默认 1.2.3.4.……的 % --v1 y1=[asum1,asum2,asum3,asum4,asum5,asum6,asum7,a ...

  2. matlab画柱状图

    论文中需要画图进行比较,感觉还是matlab画起来比较方便,先把自己画的图及matlab代码放上. y=[300 311;390 425; 312 321; 250 185; 550 535; 420 ...

  3. 用Matlab画直方图

    简介 本文介绍如何使用matlab定制自己的直方图. 关键 使用Matlab的 bar() 函数创建柱状图 bar() 画的bin的高度跟数据相关 bar() 数据每一列一个group,有几列数据就画 ...

  4. matlab画图形函数 semilogx

    matlab画图形函数 semilogx loglog 主要是学习semilogx函数,其中常用的是semilogy函数,即后标为x的是在x轴取对数,为y的是y轴坐标取对数.loglog是x y轴都取 ...

  5. 用MATLAB画函数的曲线

    用MATLAB画函数曲线 2013年8月11日 命令funtool 这是单变量函数分析的交互界面,比较方便,特别适用于y=f(x)型,即y与x分开的函数形式.见下图

  6. matlab画甘特图

    近期为发小论文一直在研究作业调度问题,好不easy把数据搞出来了,结果又被画甘特图给难住了,查了各种资料.anygantt,highchart.Jfree chart等都试了,效果都不咋好.无意中留意 ...

  7. 用matlab画两个曲面的图

    求助!!用matlab画两个曲面的图 这是我写的程序,但是运行不出来,麻烦帮我修改一下,谢谢!!clearallcloseall[x,y]=meshgrid(0:.1:60);z1=(25*y-25* ...

  8. MATLAB之折线图、柱状图、饼图以及常用绘图技巧

    MATLAB之折线图.柱状图.饼图以及常用绘图技巧 一.折线图 参考代码: %图1:各模式直接成本预测 %table0-table1为1*9的数组,记录关键数据 table0 = data_modol ...

  9. matlab画二叉树

    用matlab画如下图的二叉树. 先按树的先序遍历把结点编号,如下图所示. treeplot函数的序列用如下方法得到.从根结点开始先序遍历,依次写下父结点的编号,设根结点的父结点为0.按先序遍历,根结 ...

随机推荐

  1. PayPal 开发详解(五):创建第一个应用,获取clientId和clientSecret

    1.创建APP 2.填写应用名称->创建应用 3.获取 clientId 和 clientSecret

  2. 一个完整的菜谱客户端(android源码)(有独立后台)

    该源码是自己写的,是一个完整的菜谱类客户端.功能简单比较简单,界面比较丑,自己乱拼接的,只为学习用.功能相对完整,数据来自独立后台,通过http协议获取,全部来自真实数据.代码里面有获取数据的相应ur ...

  3. leetcode3:不重复的最长子串长度

    package hashmap; import java.util.HashMap; import java.util.Map; public class hashmap { public stati ...

  4. 三、MongoDB的创建、更新和删除

    一.MongoDB的下载.安装与部署 二.MongoDB的基础知识简介 三.MongoDB的创建.更新和删除 概要 下面开始学习MongoDB最重要也是最基础的部分:C(创建)R(查询)U(更新)D( ...

  5. c语言学习的第10天

    #include <stdio.h> int main() { int many; printf("你想看几次?"); scanf("%d",&am ...

  6. 学习c编程的第三天

    #include<stdio.h> int add(int,int); int main(){ int x=add(1,2); printf("%d",x); retu ...

  7. shell字符串操作详解

    shell字符串操作详解的相关资料. 1.shell变量声明的判断  表达式 含义 ${var} 变量var的值, 与$var相同 ${var-DEFAULT} 如果var没有被声明, 那么就以$DE ...

  8. mysql 格式化时间

    SELECT phone,chang, msg, linkid, DATE_FORMAT(mo_time, '%Y%m%d%H%i%s') FROM mo http://www.w3school.co ...

  9. php全角字符转换为半角函数 实例代码

    PHP全角半角转换函数,把目前能找到的所有全角都列出来了一个个替换吧. 之前试过网上找的通过ASCII之类的字符替换,发现很多莫名其妙的问题.最后还是换成下面的字符替换方式了,把目前能找到的所有全角都 ...

  10. DOS下更改编码方式

    使用CHCP命令,CHCP是Change Code Page的缩写. 936 简体中文GBK 437 美国英语 65001 UTF编码 如:chcp 65001则将dos窗口中的字符编码改为UTF编码 ...