matlab 图案 柱状图_[转载]画有不同阴影图案的柱状图的matlab程序代码

tiao1=[562 548 224 545 41 445 745 512];

tiao2=[47 48 57 58 54 52 65 48];

t=0:7;

[ax,h1]=plotyy(t,tiao1,t,tiao2,@bar,@plot);

set(h1,'facecolor','g');

set(ax(1),'ytick',0:100:1000);

set(ax(2),'ylim',[0 100],'ytick',0:10:100);

data = [3, 7, 5, 2;4, 3, 2, 9;6, 6, 1, 4];

b = bar(data);

ch = get(b,'children');

set(ch{1},'FaceVertexCData',[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])

set(ch{2},'FaceVertexCData',[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])

set(ch{3},'FaceVertexCData',[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])

set(ch{4},'FaceVertexCData',[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4])

(zz来源:http://hi.baidu.com/mountplorer/item/2b7e82fd226cfe733d198b9a)

在画柱状图时,利用不同的颜色区分在实际打印时经常区分不出。为了能够更清楚第表示最终结果,可采用在柱状图中打阴影的方式来表示。

然而,Matalab本身没有提供实现这种功能的函数库。下面两个函数:

% Apply Brandon's function applyhatch_pluscolor % Apply Brian's function

applyhatch_plusC(fH, '-x.', 'rkbk');实现了上述功能。

这两个函数中都调用了函数makehatch_plus源码如下(都已经调试通过,可方便使用)。

fH = gcf; colormap(jet(4)); h = bar(rand(3, 4));

legend('Apple', 'Orange', 'Banana', 'Melon', 'Location', 'EastOutside');

% Apply Brandon's function

tH = title('Brandon''s applyhatch');

applyhatch_pluscolor(fH, '-x.', 0, [1 0 1 0], jet(4));

% Apply Brian's function

set(tH, 'String', 'Brian''s applyhatch'); applyhatch_plusC(fH, '-x.', 'rkbk'); set(tH, 'String', 'Original');

代码源自:

http://www.mathworks.com/matlabcentral/fileexchange/24021-hatch-fill-patterns-plus-color-invert/content/applyhatch_pluscolor.m

function [im_hatch,colorlist] = applyhatch_pluscolor(h,patterns,CvBW,Hinvert,colorlist, ... dpi,hatchsc,lw)

%APPLYHATCH_PLUSCOLOR Apply hatched patterns to a figure in BW or Color % APPLYHATCH_PLUSCOLOR(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', '.', 'c', 'w', 'k' % (see makehatch_plus.m for more details) or

% a cell array of matrices of zeros (white) and ones (black) %

% In addition, H can alternatively be a uint8 NxMx3 matrix of the type % produced by imread. In this case, colors in this image will be % replaced with patterns as if it was a figure. A final figure window % will be generated that displays the result. The DPI argument % discussed below will be ignored if H is an image matrix. %

% APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW) binary value for choice of Color or Black % and White plots. If color is chosen the color will match that of the % current fill. 1 -> Color, anything else -> BW %

% APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT) binary value to invert the hatch. % i.e., if it is black lines with a white background, that becomes white % lines with a black background. This can either be a scalar value or a % 1xN array equal to the length of PATTERNS. When used as an array each % PATTERNS(i) will be inverted according to Hinvert(i). 1 -> Invert, % anything else -> Non Inverted %

% APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT,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 bitmap output. %

% Additional arguments: % %

[im_hatch,colorlist]

=

applyhatch_plus(h,patterns,CvBW,Hinvert,colorlist,dpi,hatchsc,linewidth)

%

% input DPI allows specification of bitmap resolution, making plot resolution % better for printing. Ignored if H is an image matrix.

% HATCHSC multiplier for hatch scale to increase size of pattern for better operation

% at higher resolutions

% default [] uses screen resolution as in % APPLYHATCH

% LINEWIDTH A scaling factor to apply to line and dot sizes % in hatching. Defaults to 1. % output IM_HATCH RGB bitmap matrix of new figure % use IMWRITE to output in desired format

% COLORLIST List of colors actually replaced. Useful info if % no colorlist initially given to function. % Colorlist will be uint8, not 0-1 scale as % originally specified. %

% Example 1: % bar(rand(3,4));

% [im_hatch,colorlist] = applyhatch_pluscolor(gcf,'-x.',0,0,[],150); % imwrite(im_hatch,'im_hatch.png','png') %

% Example 2: % bar

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值