Bar Graph in MATLAB Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report A Bar Graph is a diagrammatic representation of non-continuous or discrete variables. It is of 2 types vertical and horizontal. When the height axis is on the y-axis then it is a vertical Bar Graph and when the height axis is on the x-axis then it is a horizontal Bar Graph.In MATLAB we have a function named bar() which allows us to plot a bar graph. Syntax:bar(X,Y) where X and Y represent the x and the y axis of the plane. The X and Y both are vectors.Now let's move to some examples.Example 1: A simple Bar graph: MATLAB % Coordinates of x-axis x=100:20:160; % Coordinates of y-axis y=[22 44 55 66]; % Bar function to plot the Bar graph % Set the width of each bar to 60 percent % of the total space available for each bar % Set the bar color green bar(x,y,0.6,"green"); Output : Example 2: 3 groups of 4 bars: MATLAB % 3 groups are made with 4 bars % ";" is used to separate the groups y=[2 5 4 1; 5 3 3 1; 2 8 4 6]; % bar function to plot the bar bar(y); Output : Example 3: Display Stacked bars: MATLAB % 3 groups y=[2 5 4 1; 5 3 3 1; 2 8 4 6]; % stacked is used to stack the bars % on each other bar(y,'stacked'); Output : Example 4: Display negative bars: MATLAB % bars with negative values y=[2 5 4 -1; 5 -3 3 1; -2 8 4 6]; % bar function to display bars bar(y); Output :Example 5: Display horizontal bar graph: MATLAB % Coordinates of y axis y=[2 5 4 1]; % barh() function is used to % display bar horizontally barh(y); Output : Comment More infoAdvertise with us Next Article How to plot a Histogram in MATLAB ? P parasharraghav Follow Improve Article Tags : Software Engineering MATLAB MATLAB Similar Reads Horizontal Bar Graph Horizontal Bar Graph, also known as a Horizontal Bar Chart, is a type of graph used to represent categorical data. In a horizontal bar graph, the categories are displayed along the vertical axis, while the numerical values corresponding to each category are represented by horizontal bars along the h 10 min read Plotting Error Bars in MATLAB Error bars are a way of plotting errors on each point in a data set as vertical bars in a linear plot. MATLAB provides a simple function to plot the error bars for a given data; the errorbar() function. Syntax:errorbar(x,y,errors,...) Where, x - contains x datay- contains y dataerror - contains err 3 min read How to plot a Histogram in MATLAB ? A Histogram is a diagrammatic representation of a group of data over user-specified ranges. Basically, the histogram contains several bins. Bins are non-overlapping intervals in which the data is spread. In MATLAB we have a function named hist() which allows us to plot a bar graph. Syntax: hist(X) 2 min read Bar Plot in Matplotlib A bar plot uses rectangular bars to represent data categories, with bar length or height proportional to their values. It compares discrete categories, with one axis for categories and the other for values.Consider a simple example where we visualize the sales of different fruits:Pythonimport matplo 5 min read Create a grouped bar plot in Matplotlib A grouped bar plot is a type of bar chart that displays multiple bars for different categories side by side within groups. It is useful for comparing values across multiple dimensions, such as tracking sales across different months for multiple products or analyzing students' performance in differen 3 min read Stacked Bar Chart in R A stacked bar chart extends the standard bar chart from looking at numeric values across one categorical variable to two. Each bar in a standard bar chart is divided into a number of sub-bars stacked end to end, each one corresponding to a level of the second categorical variable. This article discu 2 min read Like