使用matlab画不同填充图案的柱状图

  • Post author:
  • Post category:其他


本人最近写论文,在性能分析图需要用到柱状图。开始时候使用不同颜色区分,但导师要求要使用不同的图案来填充。无奈,在网上搜索了一遍,发现有很多相关的文章。但是其中的代码直接拷贝到matlab中运行,根本不行。经过多次周折,终于尝试出来,现记录如下,以后或许还会用到。

1、下载别人写好的m文件,调用其中的函数。

原作者m文件下载地址:

applyhatch_plusC

2、将下载好的m文件,在matlab中打开。

File—>set path—->Add folder—->save

现在就可以使用里面的函数了。
使用matlab画不同填充图案的柱状图

3、编写自己的代码完成后,调用相应的函数即可。

Sample:

%

Example 1: basic operation using color charstring

%






bar(rand(3,6));

%






im_hatchC = applyhatch_plusC(1,’+-x.\x’,’rkgrgb’);%

%

%

Example 2: basic operation using colormatrix

%






bar(rand(3,4));

%






im_hatchC = applyhatch_plusC(1,’\-x.’,[1 0 0;0 1 0;0 0 1;0 11]);

%Example 4: basic operation with user defined patterns

%






bar(rand(3,3));

%






im_hatch =applyhatch_plusC(gcf,{makehatch_plus(‘\’,6),1-makehatch_plus

%






(‘\’,6),makehatch_plus

(‘\’,1)},’ggg’);

其中函数的具体含义可以参见下载文件原作者的说明。

下面贴上我自己的代码:


data = [39.63,186.19;2.18,19.46];

b = bar(data);

ch = get(b,’children’);

set(gca,’XTickLabel’,{‘LZCK[19]’,’Our scheme’})

legend(‘Application provider(AP)’,’Participant’);

ylabel(‘Authentication time consumption(ms)’);

im_hatchC = applyhatch_plusC(1,’|-‘,’rb’);