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 柱状图 条纹,matlab代码画条纹柱状图
http://blog.sina.com.cn/s/blog_491b86bf0100na7d.html 在论文中,图表往往发挥着极为重要的作用,好的图表将能进一步提升论文的质量.在书写论文时,很多时 ...
- matlab+字体设置大小,Matlab中如何修改字体的大小?
题目:Matlab中如何修改字体的大小? 使用Matlab有好几年了,一直以为command windows等窗口中的字体或者.m文件中的字体都是无法改变的,记忆中改过几次想改大一些都没成功,所以&q ...
- matlab画图 设置按钮,Matlab绘图操作(1)
1 二维数据曲线图 1.1 绘制单根二维曲线 plot函数的基本调用格式为:plot(x,y) 其中x和y为长度相同的向量,分别用于存储x坐标和y坐标数据. 例1 在0≤x≤2p区间内,绘制曲线 y= ...
- matlab如何设置自变量,matlab中如何指定一个函数的自变量
给出的代码抄有两个问题:1.书写错误,2113f_x表达式中5261漏写变量lam,"./(l.*(c1.*sin(h)":2.矩阵运算没4102有使用点运算符.如1653f_x表 ...
- matlab ode45设置步长,MATLAB中用ode45求解微分方程,如何设置最大步长?
如果你用过simulink里的ode45配置,我觉得你就会发现高赞就是在扯淡,你给的时间序列只是采样点,根本不是设置步长用的.我最近偷懒不想用simulink就研究了下ode45的函数配置项,在mat ...
- matlab 次坐标轴 标注,matlab标注坐标轴
matlab绘图如何添加图例/坐标轴刻度 像这个图里的 那样的图例如何添加 还有坐标轴的刻度如何用像上图的序号 首先打开电脑上的"matlab"软件,主界面如下图所示,箭头处输入代 ...
- matlab画条纹填充(Hatched Fill)图 填坑 applyhatch hardcopy
matlab画条纹填充(Hatched Fill)图 填坑 matlab功能庞大,有时也是一个很好的画图工具,今天画图过程遇到了些问题. 义愤地写下此博客!! 因为突然想结合条形图来展示实验结果会更加 ...
- matlab中bar画自定义柱状图
周末下雨实验室里做作业,发现用excel画的柱状图略丑,且达不到我想要的样子,就各种百度找到了一点技巧,记录下来,方便自己或者有需要的同学使用 我想绘制这种一正一反的柱状图,且标注在图形的左右两边,样 ...
- MATLAB | 绘图复刻(二) | 折线图+误差棒+柱状图+散点抖动+灰色背景+图片叠加
看到gzh R语言ggplot2科研绘图发布了一篇绘图复刻类文章,复刻了: Nature(IF=49.962)文章(Gut microbiota modulates weight gain in mi ...
- Matlab论文插图绘制模板第28期—柱状图(带误差棒errorbar)
在之前的文章中,分享了Matlab柱状图的绘制模板: 折线图的绘制模板: 散点图的绘制模板: 在实际应用时,很多时候需要在以上内容基础上添加误差棒. 所以,这次来分享一下带误差棒的柱状图的绘制模板,算 ...
最新文章
- 设置nginx 防止上传恶意脚本
- QT中利用Qlabel显示当前的时间:年-月-日-时-分-秒-星期
- 请求微信接口,判断用户是否关注公众号
- 1008: University
- windows server 2012 dhcp 配置故障转移
- vue 多选自动触发_Vue,初次邂逅(二)
- 管程由哪三部分组成_黄蜀葵烘干机是由哪几个部分组成的
- 【Jmeter篇】1小时轻松搞定项目接口自动化测试与数据驱动
- python安装方法mac_在Mac上删除自己安装的Python方法
- 一次性定时器 setTimeout
- 从高排到低变成小楼梯儿歌_幼儿数学儿歌,转发收藏!
- w ndows7如何清理垃圾,windows7系统下在关机时如何自动清理垃圾文件
- 小红书怎么看关键词排名?如何提升笔记自然搜索排名
- CSS总结1-来自freecode
- 荣耀8viper4android,王者荣耀职业联赛超玩会2-1险胜仙阁 积分紧追sViper
- 自兴人工智能——Python第三课(字符串和字典)
- python运行时不让电脑休眠_python – 在不中断程序的情况下休眠
- qt4 鼠标卡顿问题QBasicAtomicInt死锁导致的
- UTF-8, UTF-16, UTF-16LE, UTF-16BE的区别
- C#,数值计算,基础函数——任意位数π的数值算法源程序与数据可视化