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. Android IOS WebRTC 音视频开发总结(十一)-- stun&turn部署

    本篇文章主要介绍webrtc里面的stun,turn服务的安装与配置(转载请说明出处: http://www.cnblogs.com/lingyunhu, RTC.Blacker) 说到STUN,TU ...

  2. 【UEditor】远程上传图片到【七牛云存储】

    杂谈:最近在玩一个第三方的微信开发平台,里面的图片都是上传到[七牛云存储]的,用了一下非常的好用,支持各种语言,SDK齐全.支持全分布式系统架构以及存储技术和数据加速,于是决定将网站的图片都存储到七牛 ...

  3. jquery.qrcode.js生成二维码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. spark-submit工具参数说明

    执行时需要传入的参数说明 Usage: spark-submit [options] <app jar | python file> [app options] 参数名称 含义 --mas ...

  5. (转)浅谈HTML5与css3画饼图!

    神马系饼图? 饼图,大家都应该熟知,在统计数据对比方面,几乎处处用到.如cnzz的统计饼图 从饼图中,很形象地展示了访问者地区的分布,以扇形为块的方式拼成一个大圆. 都使用什么方法实现 目前众多站点制 ...

  6. 苹果Mac OS系统shell命令大全介绍

    基本命令 1.列出文件 ls 参数 目录名        例: 看看驱动目录下有什么:ls /System/Library/Extensions 参数 -w 显示中文,-l 详细信息, -a 包括隐藏 ...

  7. C#发送邮件源码

    介绍 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.SMTP协议属于TCP/IP协议 ...

  8. 04-树5 Root of AVL Tree

    平衡二叉树 LL RR LR RL 注意画图理解法 An AVL tree is a self-balancing binary search tree. In an AVL tree, the he ...

  9. Linux学习-0626

    6.26 Linux的安装1.下载镜像包.iso,启动时设置光盘的包是安装包,就可以看到完成安装流程 安装CentOS 5.52.安装时分区,swap分区,根分区... Linux管理工具:1.Sec ...

  10. Oracle数据迁移至MySQL

    ORACLE DB: 11.2.0.3.0 MYSQL DB: 5.5.14 因项目需求,需要将ORACLE生产中数据迁移至MYSQL数据库中作为初始数据,方法有如下几种: 1.ORACLE OGG ...