Navigation

Operators and Keywords

Function List:

C++ API

: barh (y)
: barh (x, y)
: barh (…, w)
: barh (…, style)
: barh (…, prop, val, …)
: barh (hax, …)
: h = barh (…, prop, val, …)

Produce a horizontal bar graph from two vectors of X-Y data.

If only one argument is given, it is taken as a vector of Y values and the X coordinates are the range 1:numel (y).

The optional input w controls the width of the bars. A value of 1.0 will cause each bar to exactly touch any adjacent bars. The default width is 0.8.

If y is a matrix, then each column of y is taken to be a separate bar graph plotted on the same graph. By default the columns are plotted side-by-side. This behavior can be changed by the style argument which can take the following values:

"grouped" (default)

Side-by-side bars with a gap between bars and centered over the Y-coordinate.

"stacked"

Bars are stacked so that each Y value has a single bar composed of multiple segments.

"hist"

Side-by-side bars with no gap between bars and centered over the Y-coordinate.

"histc"

Side-by-side bars with no gap between bars and left-aligned to the Y-coordinate.

Optional property/value pairs are passed directly to the underlying patch objects.

If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca.

The optional return value h is a graphics handle to the created bar series hggroup. For a description of the use of the bar series, see ‘bar’.

See also: bar, hist, pie, plot, patch.

Demonstration 1

The following code

 clf;
 x = rand (10, 1);
 barh (x);
 title ("barh() graph");

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 h = barh (rand (5, 3));
 set (h(1), "facecolor", "r");
 set (h(2), "facecolor", "g");
 set (h(3), "facecolor", "b");
 title ("barh() graph w/multiple bars");

Produces the following figure

Figure 1

Package: octave