| Contents | Index |
![]()
To graph selected variables, use the Plot Selector
in the Workspace
Browser, or use the Figure Palette Plot Catalog. Manipulate graphs
in plot edit mode with the Property Editor. For
details, see Plotting Tools — Interactive Plotting in the MATLAB Graphics
documentation and Creating Plots from the Workspace Browser in the MATLAB Desktop
Tools and Development Environment documentation.
barh(Y)
barh(X,Y)
barh(...,width)
barh(...,'style')
barh(...,'bar_color')
barh(...,'PropertyName',PropertyValue,...)
barh(axes_handle,...)
h = 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 x-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. The default is to assign an appropriate progression of tick values according to the data. If you want the x-axis scale to end exactly at the last bar, set the axis limits as,
set(gca,'XLim',[1 length(Y)])
barh(X,Y) draws a bar for each element in Y at locations specified in x, where X is a vector defining the x-axis intervals for the vertical bars. The x-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(...,'style') specifies the style of the bars. 'style' is 'grouped' or 'stacked'. Default mode of display ia 'grouped'.
'grouped' displays m groups of n vertical bars, where m is the number of rows and n is the number of columns in Y. The group contains one bar per column in Y.
'stacked' displays one bar for each row in Y. The bar height 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.
'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 x-ticks, rather than making bars span x-ticks as the histc option does.
Note When you use either the hist or histc option, you cannot also use parameter/value syntax. These two options create graphic objects that are patches rather than barseries. |
barh(...,'bar_color') displays all bars using the color specified by the single-letter abbreviation 'r', 'g', 'b', 'c', 'm', 'y', 'k', or 'w'.
barh(...,'PropertyName',PropertyValue,...) sets the named property or properties to the specified values. You cannot speciy properties when hist or histc options are used. See the barseries property descriptions for information on what properties you can set.
barh(axes_handle,...) plots into the axes with the handle axes_handle instead of into the current axes (gca).
h = barh(...) returns a vector of handles to barseries graphics objects, one for each created. When Y is a matrix, barh creates one barseries graphics object per column in Y.
Creating a bar graph of an m-by-n matrix creates m groups of n barseries objects. Each barseries object contains the data for corresponding x values of each bar group (as indicated by the coloring of the bars).
Note some barseries object properties set on an individual barseries object set the values for all barseries objects in the graph. See the barseries property descriptions for information on specific properties. |
This example shows how to plot vector data using barh .
y = [75.995 91.972 105.711 123.203 131.669 ...
150.697 179.323 203.212 226.505 249.633 281.422];
figure; barh(y);

This example shows how to specify width for each bar in the graph. You can specify one or both data inputs.
figure; barh(y,0.4);

This example shows you how to specify Style for bar graph.
figure; subplot(2,2,1); barh(y,'grouped'); subplot(2,2,2); barh(y,'stacked'); subplot(2,2,3); barh(y,'hist'); subplot(2,2,4); barh(y,'histc');

This example shows how to specify color for the graph.
figure; barh(y,'r');

You can instead specify the rgb color instead of using the predefined ones. For example,
figure; barh(y,'g','EdgeColor',[1 0.5 0.5]);

This example shows how to plot vector data with two inputs x and y using barh .
x = [1900:10:2000]; figure; barh(x,y);

The default is to assign an appropriate progression of tick values according to the data. If you want the y-axis scale to end exactly at the last bar, you can change the axes YLim property, which sets the limits of the y-axis. See axes for more information.
x = [1900:10:2000]; figure; barh(x,y); set(gca,'YLim',[1 max(y)]);

You can also pass the expression with the barh function.
a = -2.9:0.2:2.9; barh(a,exp(-a.*a),'r')

This example shows how to plot matrix data using barh.
load count.dat; yMat = count(1:6,:); figure; barh(yMat);

This example shows how to set LineWidth and LineStyle for three barseries objects using the handle returned by barh.
hMulti = barh(yMat); set(hMulti,'LineWidth', 2, 'LineStyle',':');

This example creates a graph that displays three groups of bars and contains five barseries objects. Since all barseries objects in a graph share the same baseline, you can set values using any barseries object's BaseLine property. This example uses the first handle returned in h.
Y = randn(3,5); h = barh(Y); set(get(h(1),'BaseLine'),'LineWidth',2,'LineStyle',':') colormap summer % Change the color scheme

Specifying colormap assigns a specific color in the map spectrum to each handle object in the group resulting in one color for each object group.
bar | bar3 | bar3h | Barseries Properties | ColorSpec | hist | stairs

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |