Documentation

barh

Plot bar graph horizontally

Syntax

barh(y)
barh(x,y)
barh(...,宽度)
barh(...,style)
barh(...,'color')
barh(...,'PropertyName',PropertyValue,...)
barh(ax,...)
b = barh(...)

描述

Abarh图将矢量或矩阵中的值显示为水平条。

barh(y)为每个元素绘制一个水平条y。如果y是a matrix,barhgroups the bars produced by the elements in each row. They-axis scale ranges from 1 up to冗长)什么时候y是矢量,1tosize(y,1),这是行的数量,当y是矩阵。值中的值y可以是数字或持续时间值。

barh(x,y)为每个元素画一个条y在指定的位置x, 在哪里x是a vector defining locations along they设在。的location values can be nonmonotonic, but cannot contain duplicate values. Ify是a matrix,barh将每一行的元素分组为yat corresponding locations inx。值中的值xcan be numeric, datetime, duration, or categorical values.

barh(...,宽度)设置相对条形宽度并控制组内条的分离。默认值宽度0.8, so if you do not specifyx,一组内的条具有轻微的分离。如果宽度1, the bars within a group touch one another. The value of宽度必须是标量。

barh(...,style)指定条形的样式。指定风格作为这些价值之一:

  • “分组”显示mgroups ofn酒吧,哪里m是the number of rows andn是列中的数量y。Each group contains one bar per column iny。这是默认值。

  • “堆积”显示one bar for each row iny。的bar length is the sum of the elements in the row. Each bar is multicolored, with colors corresponding to distinct elements and showing the relative contribution each row element makes to the total sum. Thebarhfunction treats all vectors as column vectors. Ify是长度的向量n, thenbarh显示nbars.

  • 'histc'以直方图格式显示图形,其中杆相互接触。

  • 'hist'also displays the graph in histogram format, but centers each bar over the tick value, rather than making bars span the tick values as the历史coption does.

不te

当您使用任何一个历史或者历史c选项,您也不能使用参数/值语法。这两个选项创建Patch对象而不是酒吧objects.

barh(...,'color')使用单字母缩写指定的颜色显示所有条'r','g','b','c','M','y','K', or'w'

barh(...,'PropertyName',PropertyValue,...)将命名属性或属性设置为指定值。当您无法指定属性时历史或者历史c使用选项。看栏属性了解更多信息。

barh(ax,...)plots into the axesax而不是进入电流轴(gca)。

b = barh(...)返回一个向量酒吧objects. Wheny是a matrix,barhcreates one酒吧object per column iny。Each酒吧object comprises a set of bars that have the same color. Usebto change properties for all bars in a酒吧目的。

例子

全部收缩

创建水平条形图vector data.

y = [57,91,105,123,131,150,。。。170,203,226.5,249,281.4];图barh(y)

barh为每个元素绘制一个水平条y

指定the bar width to 0.4.

y = [57,91,105,123,131,150,。。。170,203,226.5,249,281.4];figure; width = 0.4; barh(y,width);

Create a figure with four subplots. In each subplot, create a horizontal bar graph using a different style option for each graph.

x = [2,4]; y = [1,2,3,4;。。。5,6,7,8]; figure; subplot(2,2,1); barh(x,y,“分组”);% groups by row标题('Grouped Style') subplot(2,2,2); barh(x,y,“堆积”);%堆叠每行堆叠值标题(“堆叠风格”) subplot(2,2,3); barh(x,y,'hist');% centers bars over x values标题('hist Style') subplot(2,2,4); barh(x,y,'histc');% spans bars over x values标题('histc Style')

创建水平条形图,然后将条形的颜色更改为红色。

y = [57,91,105,123,131,150,。。。170,203,226.5,249,281.4];图barh(Y,'r')

Create a horizontal bar graph with categorical values along they设在。默认,the categories display in alphabetical order.

c =分类({'apples','梨','oranges'}); prices = [1.23 0.99 2.3]; barh(c,prices)

创建水平条形图并将线宽度设置为2。使用RGB三重态为条形设置面部颜色和边缘颜色。

y = [57,91,105,123,131,150,。。。170,203,226.5,249,281.4];图barh(Y,“ faceColor”,[0,0.5,0.5],。。。'EdgeColor',[0,0,0.9],。。。'LineWidth',2)

定义xy作为数据向量。

x = 1900:10:2000; y = [57,91,105,123,131,150,。。。170,203,226.5,249,281.4];

创建水平条形图the data iny。Usexto specify the bar locations along they设在。

figure barh(x,y)

加载数据集count.dat,返回三列矩阵,count。Storeyas the first six rows ofcount

loadcount.daty = count(1:6,:);

创建水平条形图matrixy

图barh(y)

默认,barh按行分组。

加载数据集,count.dat,返回三列矩阵,count。定义yas the first four rows of count.

loadcount.daty = count(1:4,:);

创建水平条形图yusing a dotted line style. Return the three bar series handles.barhcreates a bar series for each column iny

h = barh(y,'linestyle',':');

使用手柄hto set different property values for each bar series. Change the face color of the first bar series to cyan by setting theFaceColorproperty to青色。Set the face color for the third bar series using an RGB triplet.

Starting in R2014b, you can use dot notation to set properties. If you are using an earlier release, use theset功能。

h(1).faceColor ='青色';h(3).faceColor = [0,0.5,0.5];

加载数据集count.dat,返回三列矩阵,count。Storeyas the first six rows ofcount

loadcount.daty = count(1:6,:);

创建水平条形图y和set the basevalue to 25.

图barh(Y,'BaseValue',25)

在R2006a之前引入

这个话题有帮助吗?