Matlab中画有阴影的柱状图
在画柱状图时,利用不同的颜色区分在实际打印时经常区分不出。 为了能够更清楚第表示最终结果,可采用在柱状图中打阴影的方式来表示。
然而,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');
代码源自:
/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 h