matlab bar 填充花纹,[转载]Matlab绘制柱状图采用不同图案填充
说明:在调用applyhatch前,按照自己的需要对Matlab自动绘制的图片编辑。
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 3
% 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 1:
% bar(rand(3,4));
% applyhatch(gcf,'-x.');
%
% Example 2:
% colormap(cool(6));
% pie(rand(6,1));
% legend('Jan','Feb','Mar','Apr','May','Jun');
% applyhatch(gcf,'|-+./');
%
% 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 == 2
colorlist = [];
end
bits = hardcopy(h,'-dzbuffer','-r0');
set(h,'paperpositionmode',oldppmode);
bwidth = size(bits,2);
bheight = size(bits,1);
bsize = bwidth * bheight;
if ~isempty(colorlist)
colorlist = uint8(255*colorlist);
[colors,colori] = nextnonbw(0,colorlist,bits);
else
colors = (bits(:,:,1) ~= bits(:,:,2)) | ...
(bits(:,:,1) ~= bits(:,:,3));
end
pati = 1;
colorind = find(colors);
while ~isempty(colorind)
colorval(1) = bits(colorind(1));
colorval(2) = bits(colorind(1)+bsize);
colorval(3) = bits(colorind(1)+2*bsize);
if iscell(patterns)
pattern = patterns{pati};
elseif isa(patterns,'char')
pattern = makehatch(patterns(pati));
else
pattern = patterns;
end
pattern = uint8(255*(1-pattern));
pheight = size(pattern,2);
pwidth = size(pattern,1);
ratioh = ceil(bheight/pheight);
ratiow = ceil(bwidth/pwidth);
bigpattern = repmat(pattern,[ratioh ratiow]);
if ratioh*pheight > bheight
bigpattern(bheight+1:end,:) = [];
end
if ratiow*pwidth > bwidth
bigpattern(:,bwidth+1:end) = [];
end
bigpattern = repmat(bigpattern,[1 1 3]);
color = (bits(:,:,1) == colorval(1)) & ...
(bits(:,:,2) == colorval(2)) & ...
(bits(:,:,3) == colorval(3));
color = repmat(color,[1 1 3]);
bits(color) = bigpattern(color);
if ~isempty(colorlist)
[colors,colori] = nextnonbw(colori,colorlist,bits);
else
colors = (bits(:,:,1) ~= bits(:,:,2)) | ...
(bits(:,:,1) ~= bits(:,:,3));
end
colorind = find(colors);
pati = (pati + 1);
if pati > length(patterns)
pati = 1;
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(1:2) figsize(3) figsize(4)+1]);
set(imaxes,'position',[0 0 figsize(3)
figsize(4)+1],'visible','off');
set(newfig,'visible','on');
function [colors,out] = nextnonbw(ind,colorlist,bits)
out = ind+1;
colors = [];
while out <= size(colorlist,1)
if isequal(colorlist(out,:),[255 255 255]) | ...
isequal(colorlist(out,:),[0 0 0])
out = out+1;
else
colors = (colorlist(out,1) == bits(:,:,1)) &
...
(colorlist(out,2) == bits(:,:,2)) & ...
(colorlist(out,3) == bits(:,:,3));
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
%
n = 6;
A=zeros(n);
switch (hatch)
case '/'
A = fliplr(eye(n));
case ''
A = eye(n);
case '|'
A(:,1) = 1;
case '-'
A(1,:) = 1;
case '+'
A(:,1) = 1;
A(1,:) = 1;
case 'x'
A = eye(n) | fliplr(diag(ones(n-1,1),-1));
case '.'
A(1:2,1:2)=1;
otherwise
error(['Undefined hatch pattern "' hatch '".']);
end
matlab bar 填充花纹,[转载]Matlab绘制柱状图采用不同图案填充相关推荐
- matlab内存管理工具,[转载]MATLAB内存管理
今天用Matlab跑程序,由于数据量太大,又出现 Out of memory. Type HELP MEMORY for your options.的问题.看到这篇文章非常实用,转过来方便查阅~ 用 ...
- matlab 箱图 保存,[转载]Matlab图保存方法
bar(randn(10,1)) print(gcf,'-r300','-dpdf','example1.pdf'); print(gcf,'-r300','-djpeg','example2.jpe ...
- matlab的dft谱分析,[转载]Matlab中DFT在连续信号谱分析中的应用
本来是想用Matlab做通信课的模拟调制分析的,结果弄一个时频变换就吭哧了两三天时间,把原来的老底信号系统.DSP的书又翻出来看,总算稀里糊涂画出来了..... 所谓信号的谱分析,就是时频域转换,变成 ...
- matlab 3个纵坐标,[转载]Matlab plotyy画双纵坐标图实例
Matlab plotyy画双纵坐标图实例 x = 0:0.01:20; y1 = 200*exp(-0.05*x).*sin(x); y2 = 0.8*exp(-0.5*x).*sin(10*x); ...
- matlab legend 太大,[转载]MATLAB中调整legend的大小位置
MATLAB中plot命令绘图微调的几个注记 1.MATLAB如何从硬盘读取文件. 2.如何微调subplot子图的位置. 3.plot命令绘曲线时,曲线上的标志如何调整大小. 4.坐标轴的调整. 6 ...
- matlab中griddata函数,[转载]matlab中griddata函数应用示例
知道一系列点的坐标如下(1.486,3.059,0.1);(2.121,4.041,0.1);(2.570,3.959,0.1);(3.439,4.396,0.1);(4.505,3.012,0.1) ...
- matlab 三维图像配准,[转载]Matlab实现多种图像配准(转)
本文讲述如何利用Matlab Image Processing Toolbox中的图像配准工具实现线性正投影.仿射.投影.多项式.分段线性.局部加权平均配准的过程. 实验平台 X86 PC,Windo ...
- matlab imagesc参数设置,[转载]matlab 中imagesc的用法
imagesc(A) 将矩阵A中的元素数值按大小转化为不同颜色,并在坐标轴对应位置处以这种颜色染色 imagesc(x,y,A) x,y决定坐标范围,x,y应是两个二维向量,即x=[x1 x2],y= ...
- matlab保存数据save,[转载]matlab中save,load使用方法
功能描述]存储文件 [软件界面]MATLAB->File->Save Workspace As将变量存入硬盘中指定路径. [函数用法] save:该函数将所有workspace中变量用二进 ...
- matlab堆栈的思想,[转载]Matlab源代码:堆栈类Stack的实现
Matlab源代码:堆栈类Stack的实现 -- by benbenknight 自己编写了一个堆栈类Stack,供大家分享. 类的成员函数清单如下: Stack STACK 堆栈对象Stack的构造 ...
最新文章
- 面向对象三大特征——继承
- PAT练习之字符串处理
- 5-1 Django的路由层(urlconf)
- Py之jieba:Python包之jieba包(中文分词最好的组件)简介、安装、使用方法之详细攻略
- mysql 上级组织参数值_MySQL参数group_replication_consistency说明
- Fiddler二次开发 C#
- 18款帝豪gl车机升级_提车2020款帝豪GL,空间也不错,动力也够用的
- BZOJ1485: [HNOI2009]有趣的数列
- fofa自动化爬虫脚本更新+详解
- 常用的几种卷积神经网络介绍
- Django(三)模板
- etcd部署简单说明
- 开了个股票模拟仓来玩玩
- HBase常用操作备忘
- Zabbix 3.0入门到企业实战阅读目录
- debian nginx php配置文件,在debian上安装配置nginx + php-FPM + APC
- docker下配置linux7.2
- 开源开放 | Gowild 狗尾草“七律”知识图谱进入 OpenKG,开放 8000 万中文百科知识三元组数据...
- 方差及常见分布的方差计算与推导
- 负数除以正数余数如何求_关于数学中求余数问题的一个简单方法
热门文章
- 基于exosip 编写呼叫流程实例
- 迅捷fw313r服务器无响应,FAST迅捷FW313R路由器的固件更新教程
- 锐捷交换机常用命令速查
- JAVA: 初级项目之基于Swing界面的仿QQ(一)
- 介绍一个可以轻松下载病毒样本的数据库
- MinGW-w64的安装及配置教程
- 视频显示服务器无返回播放器,播放器没有办法播放
- p1口实验_【正点原子FPGA连载】第二章 实验平台简介-摘自【正点原子】开拓者 FPGA 开发指南...
- 第三十四讲项目2.1-麻烦的累加涨功夫
- onlyoffice源码编译环境搭建破解