matlab 图案 柱状图_科学网—使用matlab绘画柱状图,且使用不同的图案填充 - 时杰的博文...
在论文中,图表往往发挥着极为重要的作用,好的图表将能进一步提升论文的质量。在书写论文时,很多时候需要绘制柱状图,然而不同的柱状图如果采用颜色区分,当论文打印以后,视觉效果大打折扣,甚至无法区分。在遇到这个问题时,我通过网站论坛搜索,终于找到了在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
效果如下图所示
转载本文请联系原作者获取授权,同时请注明本文来自时杰科学网博客。
链接地址:http://blog.sciencenet.cn/blog-40165-308439.html
matlab 图案 柱状图_科学网—使用matlab绘画柱状图,且使用不同的图案填充 - 时杰的博文...相关推荐
- matlab mic系数_科学网—最大信息系数 (Maximal Information Coefficient, MIC)详解(1) - 彭勇的博文...
最大信息系数 (Maximal Information Coefficient, MIC)详解(1) 四年前看过的一篇论文,当时还在组会上报告过,很确信当时把它弄懂了,由于当时是用机器学习的方法来做预 ...
- matlab 更换坐标轴_科学网—【Matlab】坐标轴的设置 - 叶瑞杰的博文
使用matlab的绘图函数plot绘图时系统默认设置了一些属性,例如坐标轴字号大小等并根据情况自动设置坐标轴显示的上下限,这些属性可以通过函数灵活改动,此处总结一小部分. figure; %设置坐标轴 ...
- matlab stract结构_科学网—[MATLAB]方便快捷读取结构体里数个结构体内的数据 - 胡振东的博文...
clc;clear;close all cd F:\01_DATA\Data_process\Glide load('Glide0.mat') % Glide0.mat里的Glide结构体有G1,G2 ...
- matlab图片白边_科学网—[原创] matlab输出图片无白边 - 杨光的博文
今天要做一个gif动画,可惜GIF Movie Gear不认eps文件,无奈只好输出png格式的文件,麻烦来了,输出的图像有白边!之前挥之不去的问题再一次来了.在网上搜索一个多小时,都是说什么先ims ...
- matlab nan 无色_科学网—Matlab 关于NaN值的填充 - 肖鑫的博文
以前认为很麻烦的事往往一行命令就能搞定,代码如下 figure('position',[100 100 600 500],'PaperPositionMode', 'auto') m_proj('Sa ...
- matlab pdepe函数边界,科学网-使用MATLAB中pdepe函数求解一维偏微分方程-邓浩鑫的博文...
由于自己科研水平较低,记录的各种体会更多的是给自己做个小结,错误之处,欢迎大家指正. 使用MATLAB求解偏微分方程或者方程组,大致有三类方法.第一种是使用MATLAB中的PDE Toolbox,PD ...
- matlab排序 第二条件,科学网—【MATLAB技术贴】矩阵多条件排序 - 崔健的博文
针对矩阵的多个条件排序问题,可以采用如下函数(以列为例):sortrows 具体参数如下: 1.先按照第二列的升序排序,然后按照第一列的升序排序:sortrows(a,[2,1]) 2.先按照第二列的 ...
- matlab音乐键盘模拟,科学网—[原][Matlab][04] Midi音乐键盘 - 王楠的博文
以前在网上读到一个用matlab播canon音乐的源码感觉很有意思,但声音还不够好. 于是想做个自己的音乐播放器,有键盘,有对应的钢琴声音,读取乐谱就能播.如下. (1)按键的音高与频率 从1到下一个 ...
- matlab print 保留颜色,科学网—解决matlab saveas printf保存图片时 colorbar中的字体颜色发生改变 - 肖鑫的博文...
matlab在画多个图片循环保存时很容易出现看到的图跟保存的图片不一样,最常见的是大小不同导致坐标轴拉伸变形,主要是图片分辨率跟屏幕分辨率不同的原因,这个可以通过在设置figure时,固定画布大小解决 ...
- matlab 数组去掉0,科学网—在Matlab环境下去除矩阵中的零向量 - 李航的博文
主要用到了any()函数. e.g.1 找到矩阵中为零的列向量,并将其删除. >> a=[1,2,3;0,0,0;4,5,6;0,0,0;7,8,9]' a = 1 0 4 ...
最新文章
- h264和h265多维度区别
- axios的this指向_vue使用axios中 this 指向问题
- 在悬崖下得到鸿蒙塔,第一次夜宿在悬崖峭壁上:垂直高度356米,峡谷深渊就在边上...
- 指针01 - 零基础入门学习C语言41
- [转载]拉格朗日乘子法如何理解?
- Android长时间后台运行Service
- 利用机器学习实现微信小程序-加减大师自动答题
- Ajax核心:XMLHTTP组件相关技术资料
- 关于nagios监控系统添加主机和服务脚本
- SolidWorks学习日记
- 安卓机型app的编译与反编译 apk文件的简单说明与解析
- 常用的页面布局(两栏布局、三栏(圣杯、双飞翼)布局)
- 三星android 安卓版本怎么升级包,三星A70官方安卓9固件系统线刷升级更新包:BRI-A7050ZHU3ASJ1...
- 魔窗使用笔记(穿透微信)
- A Comparison of CNN-Based and Hand-Crafted Keypoint Descriptors论文阅读笔记
- 【冰糖R语言】Pearson、Spearman相关性及其显著性 cor() rcorr()
- 线性代数拾遗(二):线性方程组的解集及其几何意义
- 蓝桥杯javac组我们的征途是星辰大海
- aria2c指定下载存储路径的一个问题(可能不算bug)
- 西瓜皮18.6.27
热门文章
- SDRAM控制器仿真
- html 卫星地图显示地名,卫星图看:河南10个名字非常好听的县(区),你认识几个?...
- 计算机专业英语思维导图
- fw313r手机登录_迅捷(FAST)fw313r路由器初始密码_登录密码是多少?-192路由网
- Python常用软件包,python使用的软件
- 苹果系统itunes连iphone连不上服务器,iphone连不上itunes怎么办,iphone连不上itunes的解决办法...
- google linux桌面快捷方式,centos7 rhel7 linux下怎么安装google chrome 设置谷歌浏览器桌面快捷方式...
- 汇编语言教程 -- 开始
- Vue.js 基础入门
- python七月超有用的十大开源代码(2019)