当前位置: 首页>編程日記>正文

matlab中如何画柱状图,如何在用Matlab画柱状图

matlab中如何画柱状图,如何在用Matlab画柱状图

画柱状图比较方便的还是Excel,不过作为逼格比较高的我们有必要学习一下如何用Matlab玩转柱状图。

y=[67.84 68.89 71.54 71.67;67.17 69.47 73.41 73.14];

b=bar(y);

grid on;

ch = get(b,’children’);

set(gca,’XTickLabel’,{‘Dataset 1′,’Dataset 2′})

% 不知道为什么会报错,在Matlab2009,2011测试都不行

% set(ch,’FaceVertexCData’,[1 0 0;0 1 0; 0 0 1; 1 0 1]);

legend(‘Fea. 1′,’Fea. 2′,’Fea. 3′,’Fea. 4’);

xlabel(‘Datasets’);

ylabel(‘Precision’);

另一个比较好用的:

>> a=[1 2 3];

>> b=diag(a);

>> c=bar(b,’stack’);

>> color=[0 0 0.75;0 1 0;1 0.5 0];

>> for i=1:3

set(c(i),’FaceColor’,color(i,:));

end

====================但是问题来了,上面方式是以颜色区分不同柱状的,下面我们寻思靠图案来区分的方式==============

主要参考:http://blog.sciencenet.cn/blog-40165-308439.html

http://www.aos.wisc.edu/~dvimont/matlab/Graphics_Tools/applyhatch.html

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


https://www.fengoutiyan.com/post/14477.html

相关文章:

  • matlab画矩形图
  • matlab怎么绘制柱状图和柱状图
  • matlab带星号的柱状图
  • 用matlab画
  • matlab如何画折线图
  • matlab柱状图怎么画
  • matlab画三维散点图
  • matlab画图
  • 鏡像模式如何設置在哪,圖片鏡像操作
  • 什么軟件可以把圖片鏡像翻轉,C#圖片處理 解決左右鏡像相反(旋轉圖片)
  • 手機照片鏡像翻轉,C#圖像鏡像
  • 視頻鏡像翻轉軟件,python圖片鏡像翻轉_python中鏡像實現方法
  • 什么軟件可以把圖片鏡像翻轉,利用PS實現圖片的鏡像處理
  • 照片鏡像翻轉app,java實現圖片鏡像翻轉
  • 什么軟件可以把圖片鏡像翻轉,python圖片鏡像翻轉_python圖像處理之鏡像實現方法
  • matlab下載,matlab如何鏡像處理圖片,matlab實現圖像鏡像
  • 圖片鏡像翻轉,MATLAB:鏡像圖片
  • 鏡像翻轉圖片的軟件,圖像處理:實現圖片鏡像(基于python)
  • canvas可畫,JavaScript - canvas - 鏡像圖片
  • 圖片鏡像翻轉,UGUI優化:使用鏡像圖片
  • Codeforces,CodeForces 1253C
  • MySQL下載安裝,Mysql ERROR: 1253 解決方法
  • 勝利大逃亡英雄逃亡方案,HDU - 1253 勝利大逃亡 BFS
  • 大一c語言期末考試試題及答案匯總,電大計算機C語言1253,1253《C語言程序設計》電大期末精彩試題及其問題詳解
  • lu求解線性方程組,P1253 [yLOI2018] 扶蘇的問題 (線段樹)
  • c語言程序設計基礎題庫,1253號C語言程序設計試題,2016年1月試卷號1253C語言程序設計A.pdf
  • 信奧賽一本通官網,【信奧賽一本通】1253:抓住那頭牛(詳細代碼)
  • c語言程序設計1253,1253c語言程序設計a(2010年1月)
  • 勝利大逃亡英雄逃亡方案,BFS——1253 勝利大逃亡
  • 直流電壓測量模塊,IM1253B交直流電能計量模塊(艾銳達光電)
  • c語言程序設計第三版課后答案,【渝粵題庫】國家開放大學2021春1253C語言程序設計答案
  • 18轉換為二進制,1253. 將數字轉換為16進制
  • light-emitting diode,LightOJ-1253 Misere Nim
  • masterroyale魔改版,1253 Dungeon Master
  • codeformer官網中文版,codeforces.1253 B
  • c語言程序設計考研真題及答案,2020C語言程序設計1253,1253計算機科學與技術專業C語言程序設計A科目2020年09月國家開 放大學(中央廣播電視大學)
  • c語言程序設計基礎題庫,1253本科2016c語言程序設計試題,1253電大《C語言程序設計A》試題和答案200901
  • 肇事逃逸車輛無法聯系到車主怎么辦,1253尋找肇事司機