barh — Create horizontal bar charts in MATLAB and RunMat.

barh creates horizontal bar charts from vector or matrix-style inputs. It returns a bar handle and supports grouped and stacked forms through the shared MATLAB/RunMat plotting handle-property system.

Syntax

h = barh(Y)
h = barh(Y, width)
h = barh(Y, width, color)
h = barh(Y, style)
h = barh(Y, Name, Value, ...)
h = barh(X, Y)
All supported barh forms
h = barh(Y)
h = barh(Y, width)
h = barh(Y, width, color)
h = barh(Y, style)
h = barh(Y, Name, Value, ...)
h = barh(X, Y)
h = barh(X, Y, width)
h = barh(X, Y, width, color)
h = barh(X, Y, style)
h = barh(X, Y, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
YNumericArrayYesBar heights as a vector or matrix.
widthNumericScalarYes0.75Fraction of available category space occupied by each bar.
colorStyleSpecYesColor shorthand or color name for all bars.
styleStyleSpecYesLayout/style token such as 'stacked' or color shorthand.
propsAnyVariadicName/value style arguments.
XNumericArrayYesCategory positions for bars.

Returns

NameTypeDescription
hNumericScalarHandle to the first rendered bar series.

Errors

IdentifierWhenMessage
RunMat:barh:InvalidArgumentHorizontal bar input arrays, style tokens, or name/value arguments are invalid.barh: invalid argument
RunMat:barh:InternalRenderer/GPU conversion fails while building horizontal bar geometry.barh: internal operation failed

How barh works

  • Vector inputs create a single horizontal bar series with implicit category positions on the y-axis.
  • Matrix inputs support grouped and stacked horizontal bar rendering workflows.
  • The returned value is a bar handle that can be queried and updated through get and set.
  • Display names, bar width, and face color participate in the shared plotting object/property model.
  • RunMat preserves the same fast GPU-backed rendering path as bar when inputs and style options can be handled by the shared bar vertex packer.

Does RunMat run barh on the GPU?

Horizontal bar rendering shares the same plotting architecture and shader vertex-packing path as vertical bar.

The builtin is a plotting sink and fusion barrier.

GPU memory and residency

barh preserves GPU residency where the shared bar geometry pipeline can consume exported buffers directly. Stacked gpuArray charts read values for stacked extent calculation, matching the existing bar stacked-bounds behavior, then render through the same GPU plotting path.

Examples

Create a basic horizontal bar chart from a vector

values = [3 5 2 9];
barh(values);

Create grouped horizontal bars from a matrix

Y = [3 5 2; 4 6 1; 5 4 3];
barh(Y);

Create stacked horizontal bars

Y = [8 15 25; 30 35 40; 50 55 62];
barh(Y, 'stacked');

Style a horizontal bar object and label it for the legend

h = barh([2 4 1 5]);
set(h, 'FaceColor', 'g', 'DisplayName', 'counts');
legend;

Using barh with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how barh changes the result.

Run a small barh example, explain the result, then change one input and compare the output.

FAQ

How is barh different from bar?

barh draws the same bar data horizontally. The y-axis is the category axis and the x-axis shows the numeric values.

bar([3 5 2 9]);   % vertical bars
barh([3 5 2 9]);  % horizontal bars
How do I create grouped vs stacked horizontal bar charts?

Pass a matrix to barh. By default, each row becomes a group with side-by-side horizontal bars. To stack them instead, pass 'stacked'.

Y = [3 5 2; 4 6 1; 5 4 3];
barh(Y);            % grouped
barh(Y, 'stacked'); % stacked
Can barh use explicit category positions?

Yes. Pass X and Y like MATLAB's barh(X,Y) form. The X values label the category positions on the vertical axis.

x = [1980 1990 2000];
y = [10 20 30];
barh(x, y);

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how barh is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.