本帖最后由 meatball1982 于 2012-5-9 19:05 编辑

bar.jpg (58.86 KB, 下载次数: 33)

2012-5-9 19:04 上传

baidu的。

主程序。

暂定好用。

颜色的可以自己定义,matlab就有。

斜线和X在applyhatch里有。

data = [96.3,92.6,71.2;95.7,93.6,83.9;96.8,94.3,78.3;95.8,92.7,80.3]

bar(data,1)

axis([0 6 0.0 100])

legend('方法','exited','Square')

set(gca,'XTickLabel',{'Img1','Img2','Img3','Img4'})

applyhatch(gcf,'\.x.')

applyhatch函数:

function applyhatch(h,patterns,colorlist)

%APPLYHATCH Apply hatched patterns to a figure

%  APPLYHATCH(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', '.'

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

%

%  APPLYHATCH(H,PATTERNS,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 low-resolution, bitmap output.

%

%  Example 1:

%    bar(rand(3,4));

%    applyhatch(gcf,'\-x.');

%

%  Example 2:

%    colormap(cool(6));

%    pie(rand(6,1));

%    legend('Jan','Feb','Mar','Apr','May','Jun');

%    applyhatch(gcf,'|-+.\/',cool(6));

%

%  See also: MAKEHATCH

%  By Ben Hinkle,

%  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(bits,2);

bheight = size(bits,1);

bsize = bwidth * bheight;

if ~isempty(colorlist)

colorlist = uint8(255*colorlist);

[colors,colori] = nextnonbw(0,colorlist,bits);

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(pattern,2);

pwidth = size(pattern,1);

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)

[colors,colori] = nextnonbw(colori,colorlist,bits);

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');

set(newfig,'position',[fpos(1:2) figsize(3) figsize(4)+1]);

set(imaxes,'position',[0 0 figsize(3) figsize(4)+1],'visible','off');

set(newfig,'visible','on');

function [colors,out] = nextnonbw(ind,colorlist,bits)

out = ind+1;

colors = [];

while out <= size(colorlist,1)

if isequal(colorlist(out,:),[255 255 255]) | ...

isequal(colorlist(out,:),[0 0 0])

out = out+1;

else

colors = (colorlist(out,1) == bits(:,:,1)) & ...

(colorlist(out,2) == bits(:,:,2)) & ...

(colorlist(out,3) == bits(:,:,3));

return

end

end

% 而applyhatch函数需要调用下面的函数

function A = makehatch(hatch)

%MAKEHATCH Predefined hatch patterns

%  MAKEHATCH(HATCH) returns a matrix with the hatch pattern for HATCH

%   according to the following table:

%      HATCH        pattern

%     -------      ---------

%        /          right-slanted lines

%        \          left-slanted lines

%        |          vertical lines

%        -          horizontal lines

%        +          crossing vertical and horizontal lines

%        x          criss-crossing lines

%        .          single dots

%

%  See also: APPLYHATCH

%  By Ben Hinkle,

%  This code is in the public domain.

n = 6;

A=zeros(n);

switch (hatch)

case '/'

A = fliplr(eye(n));

case '\'

A = eye(n);

case '|'

A(:,1) = 1;

case '-'

A(1,:) = 1;

case '+'

A(:,1) = 1;

A(1,:) = 1;

case 'x'

A = eye(n) | fliplr(diag(ones(n-1,1),-1));

case '.'

A(1:2,1:2)=1;

otherwise

error(['Undefined hatch pattern "' hatch '".']);

end

补充内容 (2013-11-7 10:52):

修改后的函数.m文件在21楼。有坛友说网上下的无法很好的运行。这个应该可以。请大家下载尝试。

有问题,请邮件我。谢谢。

matlab柱状斜线_matlab画柱状图,能否达到附件的效果。相关推荐

  1. matlab柱状斜线_Matlab:柱状图饼状图填充不同条纹

    下面就是重点:如何把上述图像转换成黑白图像,并填充不同条纹. 首先,创建名为"applyhatch.m"的函数脚本. 在同一路径下. 代码如下:--复制即可. function a ...

  2. matlab柱状斜线_Matlab小练习:按斜线方向依次赋值矩阵

    来自知乎问题,觉得挺有意思,留给学生解答之余,我也做了一番思考,得到三种解法. 题目如下: 以n=80为例, -------------------- 一.先要根据 确定矩阵的阶数 如果先生成足够大矩 ...

  3. 用echartsjs 实现动态绘制折线、柱状等图形,并实现多图联动效果

    echarts对于大数据处理后绘制折线图,柱形图等等的效果和速度都很好.下面我们介绍 怎么把封装的数据列表解析出来,动态绘图,并且实现鼠标联动效果 引入js文件: <script type=&q ...

  4. matlab绘制庞加莱截面_matlab画的相图和庞加莱截面图

    昨天刚知道什么是相图和庞加莱截面,今天用matlab实现,给我的感觉虽然能画出图但理论基础还差得远.以前我是用vc++编程,现在发现用matlab编程真是太简单了,不过简单归简单就是效率有点低与vc+ ...

  5. matlab三位画图_matlab画三维图像

    当我们学习surface命令时,已经看到了三维作图的一些端倪.在matlab中我么可以调用mesh(x,y,z)函数来产生三维图像. 首先,我们用z=cos(x)sin(y)在-2pi ≤x,y≤ 2 ...

  6. Matlab画柱状、饼状填充图(亲测可用)

    Matlab画柱状.饼状填充图 1.     把下列代码保存为名为"applyhatch.m"的文件 function applyhatch(h,patterns,colorlis ...

  7. python画柱状图-Python画柱状统计图操作示例【基于matplotlib库】

    本文实例讲述了Python画柱状统计图操作.分享给大家供大家参考,具体如下: 一.工具:python的matplotlib.pyplot 库 二.案例: import matplotlib.pyplo ...

  8. 【MATLAB基础绘图第2棒】绘制柱状/饼图填充图

    MATLAB绘制柱状填充图 方法1:hatchfill2工具 1.1 案例1:柱状图填充 1.2 案例2:饼图填充 方法2:applyhatch函数 2.1 案例1:柱状图填充 2.2 案例2:饼图填 ...

  9. Python的可视化包 – Matplotlib 2D图表(点图和线图,.柱状或饼状类型的图),3D图表(曲面图,散点图和柱状图)...

    Python的可视化包 – Matplotlib Matplotlib是Python中最常用的可视化工具之一, 可以非常方便地创建海量类型地2D图表和一些基本的3D图表.Matplotlib最早是为了 ...

最新文章

  1. Django 使用 HttpResponse 返回 json 字符串显示 Unicode 编码
  2. 基于用例的工作量估计
  3. 洛谷3224 【HAOI2012】永无乡(线段树合并)
  4. 【Linux学习】常用指令-sortunique
  5. (1)定义接口A,里面包含值为3.14的常量PI和抽象方法double area()。 (2)定义接口B,里面包含抽象方法void setColor(String c)。
  6. 【Yarn】Yarn 命令详解
  7. 升级总代分享思路_旧笔记本光驱换SSD,升级内存,改造散热还能再战5年
  8. 设计模式之观察者Observer
  9. 使用 Infiniband 实现 RDMA !IB卡介绍!下载IB 驱动 !lspci | grep Mell 查看 IB卡!
  10. js 条码枪扫描_JavaScript 扫描枪使用(一)
  11. HTML两张图片翻转,canvas实现图片镜像翻转的2种方式
  12. ps2改usb接口_PS2键盘接口改USB接口
  13. uva10066-双塔
  14. 寒假每日一题——贝茜放慢脚步
  15. Linux命令退格键变成^H的解决办法
  16. IBM李永辉:从人工智能到大数据的终点
  17. 窗——开了又关,关了又开(改编)
  18. 城市“断气”敲警钟 资源“价改”正逢时?
  19. 根据身份证号判断性别
  20. 微信公众号接口开发----退款

热门文章

  1. 静态HTML网页设计作品——生鲜超市网站设计(5页)HTML+CSS+JavaScript 学生DW网页设计作业成品 美食站
  2. 【rtsp流在Web端实时播放】使用 VUE + webrtc-steamer
  3. GCT考试之考试结果
  4. System.Data.SqlClient.SqlError: 备份集中的数据库备份与现有的 'XXX' 数据库不同。 (Microsoft.SqlServer.Smo)...
  5. UT4418最小Linux系统搭建指南
  6. 接触vsto,开发word插件的利器
  7. oftPerfect RAM Disk 内存盘管理,提高软件速度
  8. 【优质潜力刊】Elsevier旗下1区SCI, 热门前沿领域,已稳定检索37年~
  9. Postgresql关于wal日志总结,一文搞清楚它的所有概念和相关操作
  10. 中职计算机基础应用知识,总发中职《计算机应用基础:基础模块》第一单元 计算机基础知识.pptx...