matlab 柱状图 条纹,matlab代码画条纹柱状图
http://blog.sina.com.cn/s/blog_491b86bf0100na7d.html
在论文中,图表往往发挥着极为重要的作用,好的图表将能进一步提升论文的质量。在书写论文时,很多时候需要绘制柱状图,然而不同的柱状图如果采用颜色区分,当论文打印以后,视觉效果大打折扣,甚至无法区分。在遇到这个问题时,我通过网站论坛搜索,终于找到了在matlab中绘制柱状图,并采用不同的图案进行表示。主要利用下面的代码。
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, bhinkle@mathworks.com
% 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, bhinkle@mathworks.com
% 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
matlab 柱状图 条纹,matlab代码画条纹柱状图相关推荐
- matlab画条纹填充(Hatched Fill)图 填坑 applyhatch hardcopy
matlab画条纹填充(Hatched Fill)图 填坑 matlab功能庞大,有时也是一个很好的画图工具,今天画图过程遇到了些问题. 义愤地写下此博客!! 因为突然想结合条形图来展示实验结果会更加 ...
- matlab中bar画自定义柱状图
周末下雨实验室里做作业,发现用excel画的柱状图略丑,且达不到我想要的样子,就各种百度找到了一点技巧,记录下来,方便自己或者有需要的同学使用 我想绘制这种一正一反的柱状图,且标注在图形的左右两边,样 ...
- matlab bar3 颜色,matlab中怎么控制柱状图标注的颜色?
满意答案 lastdargo 推荐于 2016.01.18 采纳率:45% 等级:10 已帮助:818人 一.利用bar3画一个矩阵的柱状图时,如何改变显示的颜色,让它根据数据大小的不同显示不同 ...
- matlab绘制y x 3 x 1,怎样画x^2+(y-x^(2/3))^2=1的图像,用matlab可以吗?代码是什么?...
答:也可以用MathCAD MathCAD可以像Word那样方便的输入各种公式,并且公式的写法同手写方式是完全一致的.绘图等更不在话下.如果是教学,撰文等,MathCAD比Matlab好用. 如上.祝 ...
- 如何用Python语言编写源程序,读取Excel中数据,并画出柱状图?
现在,随着计算机的普及,以及数据量的增多,对大型数据的分析已经是我们手算不能解决的了,必须借助计算机:那么,学习计算机其实也和我们学习中文.英文一样,要学习他们的写作规则,掌握其中原理.所以,我们首先 ...
- php柱状图html代码,html5生成柱状图(条形图)效果的实例代码
下面小编就为大家分享一篇html5生成柱状图(条形图)效果的实例代码.小编觉得挺不错的,现在分享给大家,也给大家一个参考.一起跟随小编过来看看吧 XML/HTML Code复制内容到剪贴板 (func ...
- python画柱状图-Python:Matplotlib 画曲线和柱状图(Code)
编辑推荐: 本文讲了对数坐标图,极坐标图像,柱状图,散列图,由离散的点构成的,3D图像,主要是调用3D图像库,希望对大家有帮助. 本文来自于csdn,由火龙果软件Delores编辑,推荐. 首先补充一 ...
- matlab中应用surf函数画球形物体的三维坐标变换,从球坐标系转换到笛卡尔坐标系
在Matlab中采用surf函数画三维图时,该函数使用笛卡尔坐标系绘制图形,因此在某些球形图案的绘制中,直接使用(theta,phi,z)参数无法得到球形图案,需要将图案对应的点从球坐标转变为笛卡尔坐 ...
- matlab提取数据画图,matlab提取excel表格数据画图-如何将Excel中的数据导入MATLAB并在MATLAB中画出图......
在matlab上如何导入excel表格然后画图 工具:matlab 2018b 1.打开matlab,点击主页下面导入数据,可以导入excel数据,在此将自己命名的huitushuju文件导入: 2. ...
最新文章
- 谁说女生不能搞IT?一名女程序员的奋斗史
- svn idea使用
- PHP大法——实验吧
- Redis 基础、高级特性与性能调优 | 高薪必备
- python链接hbase模块_HBase实战(1):使用Python连接Hbase数据库
- JAVA入门_多线程_邮局派发信件
- JDK1.8并发包中的类
- H.264(MPEG-4 AVC)级别(Level)、DPB 与 MaxDpbMbs 详解
- SAP Spartacus本地启动时的白屏问题分析
- 《Sibelius 脚本程序设计》连载(十四) - 2.1 注释、语句、语句块
- 考研英语核心词汇辨析(黑魔方系列2007版之十二)
- 内存分析工具 MAT 的使用
- Python——生成一个大文件ips.txt,要求1200行 ,每行随机为172.25.254.0/24段的ip(京东二面笔试题)
- B端评分卡在中小企业贷款中使用的三个阶段
- Widget、MainWindow和Dialog的选择使用
- R语言ETL工程系列:读写(read/write)
- jpeglib的jpeg_finish_compress函数疑似越界
- 中频逆变IGBT控制板 感应加热电源 中高频电阻焊电源逆变技术
- 索尼rx1r人脸识别_徕卡Q2 索尼rx1r2对比
- 史上最全的数据库面试题,面试前刷一刷!
热门文章
- 什么叫VI、及VI的设计规范
- android elevation 白色,使用android:elevation在LinearLayout上投射阴影
- Share:电脑右下角 今日热文 广告和图标怎么关闭
- java 时间戳间隔_JAVA判断两个时间戳,相隔多少分钟
- 2019十佳DevOps工具,你用了几个?
- 学习GNU Emacs命令速查表(三)
- 无线网怎么建立虚拟服务器,Win7创建虚拟WiFi热点共享的教程
- 在移动设备上实时执行的DNN权重修剪中缺失但令人满意的稀疏性
- 串行干扰消除matlab仿真,串行干扰消除求详解
- 《构建之法》第1、2、16章阅读与思考