资源描述:
《matlab中画有阴影的柱状图》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、在画柱状图时,利用不同的颜色区分在实际打印时经常区分不出。为了能够更清楚第表示最终结果,可采用在柱状图中打阴影的方式来表示。然而,Matalab本身没有提供实现这种功能的函数库。下面两个函数:%ApplyBrandon'sfunctionapplyhatch_pluscolor%ApplyBrian'sfunctionapplyhatch_plusC(fH,'-x.','rkbk');实现了上述功能。这两个函数中都调用了函数makehatch_plus源码如下(都已经调试通过,可方便使用)。fH=gcf;colormap(jet(4));h=bar(
2、rand(3,4));legend('Apple','Orange','Banana','Melon','Location','EastOutside');%ApplyBrandon'sfunctiontH=title('Brandon''sapplyhatch');applyhatch_pluscolor(fH,'-x.',0,[1010],jet(4));%ApplyBrian'sfunctionset(tH,'String','Brian''sapplyhatch');applyhatch_plusC(fH,'-x.','rkbk');set
3、(tH,'String','Original');代码源自:http://www.mathworks.com/matlabcentral/fileexchange/24021-hatch-fill-patterns-plus-color-invert/content/applyhatch_pluscolor.mfunction[im_hatch,colorlist]=applyhatch_pluscolor(h,patterns,CvBW,Hinvert,colorlist,...dpi,hatchsc,lw)%APPLYHATCH_PLUSCOLOR
4、ApplyhatchedpatternstoafigureinBWorColor%APPLYHATCH_PLUSCOLOR(H,PATTERNS)createsanewfigurefromthefigureHby%replacingdistinctcolorsinHwiththeblackandwhite%patternsinPATTERNS.TheformatforPATTERNScanbe%astringofthecharacters:%'/','','
5、','-','+','x','.','c','w','k'%(seemakehatch_pl
6、us.mformoredetails)or%acellarrayofmatricesofzeros(white)andones(black)%%Inaddition,Hcanalternativelybeauint8NxMx3matrixofthetype%producedbyimread.Inthiscase,colorsinthisimagewillbe%replacedwithpatternsasifitwasafigure.Afinalfigurewindow%willbegeneratedthatdisplaystheresult.TheDP
7、Iargument%discussedbelowwillbeignoredifHisanimagematrix.%%APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW)binaryvalueforchoiceofColororBlack%andWhiteplots.Ifcolorischosenthecolorwillmatchthatofthe%currentfill.1->Color,anythingelse->BW%%APPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT)binaryval
8、uetoinvertthehatch.%i.e.,ifitisblacklineswithawhitebackground,thatbecomeswhite%lineswithablackbackground.Thiscaneitherbeascalarvalueora%1xNarrayequaltothelengthofPATTERNS.Whenusedasanarrayeach%PATTERNS(i)willbeinvertedaccordingtoHinvert(i).1->Invert,%anythingelse->NonInverted%%A
9、PPLYHATCH_PLUSCOLOR(H,PATTERNS,CVBW,HINVERT,COL