Plot bar graph horizontally
barh(y)
barh(x,y)
barh(...,width)
barh(...,style)
barh(...,'bar_color
')
barh(...,'PropertyName',PropertyValue,...)
barh(ax,...)
b = barh(...)
A barh
graph displays the values in a vector
or matrix as horizontal bars.
barh(y)
draws one horizontal
bar for each element in y
. If y
is
a matrix, barh
groups the bars produced by the
elements in each row. The y-axis scale ranges
from 1 up to length(y)
when y
is
a vector, and 1
to size(y,1)
,
which is the number of rows, when y
is a matrix.
barh(x,y)
draws a bar for
each element in y
at locations specified in x
,
where x
is a vector defining locations along the y-axis.
The location values can be nonmonotonic, but cannot contain duplicate
values. If y
is a matrix, barh
groups
the elements of each row in y
at corresponding
locations in x
.
barh(...,width)
sets the
relative bar width and controls the separation of bars within a group.
The default width
is 0.8
, so
if you do not specify x
, the bars within a group
have a slight separation. If width
is 1
,
the bars within a group touch one another. The value of width
must
be a scalar.
barh
specifies
the style of the bars. Specify (...,style)
style
as one of
these values:
'grouped'
displays m groups
of n bars, where m is the
number of rows and n is the number of columns
in y
. Each group contains one bar per column in y
.
This is the default value.
'stacked'
displays one bar for
each row in y
. The 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. The barh
function
treats all vectors as column vectors. If y
is a
vector of length n, then barh
displays n bars.
'histc'
displays the graph in histogram
format, in which bars touch one another.
'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 histc
option
does.
Note:
When you use either the |
barh(...,'
displays
all bars using the color specified by the single-letter abbreviation bar_color
')'r'
, 'g'
, 'b'
, 'c'
, 'm'
, 'y'
, 'k'
,
or 'w'
.
barh(...,'PropertyName',PropertyValue,...)
sets
the named property or properties to the specified values. You cannot
specify properties when hist
or histc
options
are used. See Bar Series Properties for
more information.
barh(ax,...)
plots into
the axes ax
instead of into the current axes (gca
).
b = barh(...)
returns a
vector of bar series objects. When y
is a matrix, barh
creates
one bar series per column in y
. Each bar series
comprises a set of bars that have the same color. Use the bar series
object to change properties for all bars in a series.