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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Y | NumericArray | Yes | — | Bar heights as a vector or matrix. |
width | NumericScalar | Yes | 0.75 | Fraction of available category space occupied by each bar. |
color | StyleSpec | Yes | — | Color shorthand or color name for all bars. |
style | StyleSpec | Yes | — | Layout/style token such as 'stacked' or color shorthand. |
props | Any | Variadic | — | Name/value style arguments. |
X | NumericArray | Yes | — | Category positions for bars. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the first rendered bar series. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:barh:InvalidArgument | Horizontal bar input arrays, style tokens, or name/value arguments are invalid. | barh: invalid argument |
RunMat:barh:Internal | Renderer/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
getandset. - 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
barwhen 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 barsHow 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'); % stackedCan 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);Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · cla · clf · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · textscatter · textscatter3 · triplot · waitbar · wordcloud · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zoom
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.
- View the source for barh in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.