matlab柱状斜线_Matlab:柱状图饼状图填充不同条纹
下面就是重点:如何把上述图像转换成黑白图像,并填充不同条纹。
首先,创建名为“applyhatch.m”的函数脚本。
在同一路径下。
代码如下:——复制即可。
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:柱状图饼状图填充不同条纹相关推荐
- java excel 饼图,java 导入导出excle 和 生成柱状图饼状图的demo/excle数据如何转成饼状图...
在EXCEL中,如何把表格中的数据转换成饼状图? 在Excel中,把中的数据转换状图的操作步骤如下: 想转换的数据源,插入饼状图,Excel会自动根据选择的数据源生成饼状图.接下来,可以自定义饼状图的 ...
- poi导出excel文件,并生成原生图表(包括折线图,柱状图,饼状图,面积图)
前段时间,因为客户需要,要做一个导出excel文件功能,并能生成原生的图表的(不是把图片插入到excel文档),找了很多文档看,也看了很多别人的代码,个人也总结了一下,不足之处,请各位大牛谅解. 需要 ...
- Word中插入表格与柱状图饼状图技术经验分享
最近公司一个项目里要求自动生成报告功能,研究了1周多,主要实现方式是通过调用微软Office COM组件来实现操作word文档,生成段落,表格,及各种图表. 本人发现操作word地方也有几个坑人的地方 ...
- Superset 制作 地图 柱状图 饼状图
文章目录 制作地图 制作柱状图 制作饼状图 制作地图 1)创建 Chart 2)配置 Chart 3)结果图 制作柱状图 1)创建 Chart 2)配置 Chart 3)结果图 制作饼状图 1)创建 ...
- java实现将数据生成图表至excel导出(包括折线图,柱状图,饼状图)
1. 目的 根据已有数据,手动(java后台)生成图表至excel并导出.用于后台查询到数据后直接创建图表,可以代替直接使用图表信息字符串. 2. 说明 使用jfree图表绘制类库绘制图表,并生成到本 ...
- Echarst柱状图+饼状图+vue2 商品案例
最终效果展示: echarst非常简单,就是使用的数据需要按照规定的格式,往往是获取数据较难 首先前端,只需要一个div,用ref指定名称,定好宽高,就ok,div多大,图就会自适应多大 <di ...
- php 柱状 折线 组合,柱状图和折线图组合怎么用
在Excel中,有时候单一的图表类型无法满足数据的多元化展示,这时就要考虑多种图表的组合,所以本文就以柱状图和折线图的组合为例,介绍一下组合图表的制作方法. 在下图中,以年份为横坐标,营业收入用柱状图 ...
- matlab柱状斜线_matlab画柱状图,能否达到附件的效果。
本帖最后由 meatball1982 于 2012-5-9 19:05 编辑 bar.jpg (58.86 KB, 下载次数: 33) 2012-5-9 19:04 上传 baidu的. 主程序. 暂 ...
- matlab柱状斜线_Matlab小练习:按斜线方向依次赋值矩阵
来自知乎问题,觉得挺有意思,留给学生解答之余,我也做了一番思考,得到三种解法. 题目如下: 以n=80为例, -------------------- 一.先要根据 确定矩阵的阶数 如果先生成足够大矩 ...
最新文章
- matlab 罗盘图与羽毛图
- 由谈退格键的实现来学习字符编码
- 浅析Microsoft .net PetShop程序中的购物车和订单处理模块(Profile技术,异步MSMQ消息)转...
- 财务报销人员是公司亲信的弊端
- 欧拉折线法解常微分方程C语言,05常微分方程数值解.ppt
- 使用 cmd、PowerShell 等用命令行的方式创建文件及文件夹
- 中的listeners_Netty源码学习(6)-- Netty中的异步处理
- python selenium iframe怎么定位_python+selenium四:iframe查看、定位、切换
- Js toString()方法笔记
- 从Mysql数据库中导入导出表结构
- 高等数学张宇18讲 第十四讲 数学一、数学二专题内容
- 我的Latex中文报告模板
- 06540计算机网络2018年自考真题,自考06540计算机网络基本原理复习资料六
- lisp 左手钢筋_CAD左手键及使用方法
- java获取微信公众号二维码
- 争做新时代好少年主题团日活动PPT模板
- 通过echarts绘制双十一销量实时统计图表
- Watch App简介
- 两个决策树例题经典案例-代码示例
- SVLAN,CVLAN,PVLAN区别