资源简介
MATLAB实现数据的无颜色柱状图,满足一些期刊论文只能黑白打印
代码片段和文件信息
function applyhatch(hpatternscolorlist)
%APPLYHATCH Apply hatched patterns to a figure
% APPLYHATCH(HPATTERNS) 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(HPATTERNSCOLORS) 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(34));
% applyhatch(gcf‘-x.‘);
%
% Example 2:
% colormap(cool(6));
% pie(rand(61));
% legend(‘Jan‘‘Feb‘‘Mar‘‘Apr‘‘May‘‘Jun‘);
% applyhatch(gcf‘|-+./‘cool(6));
%
% 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 == 2
colorlist = [];
end
bits = hardcopy(h‘-dzbuffer‘‘-r0‘);
set(h‘paperpositionmode‘oldppmode);
bwidth = size(bits2);
bheight = size(bits1);
bsize = bwidth * bheight;
if ~isempty(colorlist)
colorlist = uint8(255*colorlist);
[colorscolori] = nextnonbw(0colorlistbits);
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(pattern2);
pwidth = size(pattern1);
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)
[colorscolori] = nextnonbw(coloricolorlistbits);
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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4600 2018-03-28 15:48 柱状图\applyhatch.m
文件 75 2018-03-28 16:07 柱状图\readme.txt
文件 356 2018-03-28 16:02 柱状图\zhuzhuangtu.m
目录 0 2018-03-28 16:05 柱状图
----------- --------- ---------- ----- ----
5031 4
- 上一篇:IOS电量测试证书Sysdiagnose
- 下一篇:crf图像显著性检测
评论
共有 条评论