|MATLAB Function Reference|
Plot bar graph (vertical and horizontal)
A bar graph displays the values in a vector or matrix as horizontal or vertical bars.
draws one bar for each element in
Y is a matrix,
bar groups the bars produced by the elements in each row. The x-axis scale ranges from 1 up to
Y is a vector, and
size(Y,1), which is the number of rows, when
Y is a matrix. The default is to scale the x-axis to the highest x-tick on the plot, (a multiple of 10, 100, etc.). If you want the x-axis scale to end exactly at the last bar, you can use the default, and then, for example, type
at the MATLAB prompt.
draws a bar for each element in
Y at locations specified in
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,
bar groups the elements of each row in
Y at corresponding locations in
sets the relative bar width and controls the separation of bars within a group. The default
0.8, so if you do not specify
x, the bars within a group have a slight separation. If
1, the bars within a group touch one another.
bar(...,' specifies the style of the bars.
'group' is the default mode of display.
'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
'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.
bar(..., displays all bars using the color specified by the single-letter abbreviation
bar(axes_handles,...) and barh(axes_handles,...)
plot into the axes with handle
axes_handle instead of the current axes (
h = bar(...)
returns a vector of handles to barseries graphics objects.
bar creates one barseries graphics object per column in
barh(...) and h = barh(...)
create horizontal bars.
Y determines the bar length. The vector
x is a vector defining the y-axis intervals for horizontal bars. The x-values can be nonmonotonic, but cannot contain duplicate values.
Backward Compatible Versions
hpatches = bar('v6',...) and hpatches = barh('v6',...)
return the handles of patch objects instead of barseries objects for compatibility with MATLAB 6.5 and earlier. See patch object properties for a discussion of the properties you can set to control the appearance of these bar graphs.
See Plot Objects and Backward Compatibility for more information.
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 that some barseries object properties set on an individual barseries object set the values for all barseries objects in the graph. See the property descriptions for information on specific properties.
Single Series of Data
This example plots a bell-shaped curve as a bar graph and sets the colors of the bars to red.
Bar Graph Options
This example illustrates some bar graph options.
Setting Properties with Multiobject Graphs
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
Area, Bar, and Pie Plots for related functions
Bar and Area Graphs for more examples
© 1994-2005 The MathWorks, Inc.