RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • addpoints
    • ancestor
    • animatedline
    • area
    • axes
    • axis
    • bar
    • barh
    • box
    • caxis
    • cla
    • clf
    • clim
    • colorbar
    • colorcube
    • colormap
    • colororder
    • contour
    • contour3
    • contourf
    • copyobj
    • daspect
    • datacursormode
    • dataTipTextRow
    • errorbar
    • fcontour
    • figure
    • fill
    • fill3
    • findobj
    • fsurf
    • gca
    • gcf
    • get
    • gobjects
    • grid
    • groot
    • heatmap
    • hgload
    • hgsave
    • hidden
    • hist
    • histogram
    • histogram2
    • hold
    • image
    • imagesc
    • imshow
    • legend
    • line
    • linkaxes
    • loglog
    • mesh
    • meshc
    • openfig
    • opengl
    • pan
    • parula
    • patch
    • pie
    • plot
    • plot3
    • plotmatrix
    • plotyy
    • polarhistogram
    • polarplot
    • polarscatter
    • print
    • quiver
    • quiver3
    • ribbon
    • saveas
    • savefig
    • scatter
    • scatter3
    • semilogx
    • semilogy
    • set
    • sgtitle
    • shading
    • sphere
    • stackedplot
    • stairs
    • stem
    • subplot
    • subtitle
    • suptitle
    • surf
    • surfc
    • text
    • textscatter
    • textscatter3
    • title
    • triplot
    • view
    • waitbar
    • wordcloud
    • xlabel
    • xlim
    • xline
    • xscale
    • xtickangle
    • xtickformat
    • xticklabels
    • xticks
    • ylabel
    • ylim
    • yline
    • yscale
    • ytickangle
    • ytickformat
    • yticklabels
    • yticks
    • zlabel
    • zlim
    • zoom

histogram2 — Create two-dimensional histogram chart objects in MATLAB and RunMat.

histogram2(X,Y) bins paired observations with MATLAB-compatible histcounts2 semantics and creates a handle-backed 2-D histogram chart. RunMat renders the chart as a colormapped surface: DisplayStyle "bar3" uses bin counts as surface height, while "tile" renders a flattened heatmap-style view.

Syntax

h = histogram2(X, Y)
h = histogram2(X, Y, bins)
h = histogram2(X, Y, binsX, binsY)
h = histogram2(X, Y, Name, Value, ...)
h = histogram2(ax, X, Y)
h = histogram2(ax, X, Y, bins)
All supported histogram2 forms
h = histogram2(X, Y)
h = histogram2(X, Y, bins)
h = histogram2(X, Y, binsX, binsY)
h = histogram2(X, Y, Name, Value, ...)
h = histogram2(ax, X, Y)
h = histogram2(ax, X, Y, bins)
h = histogram2(ax, X, Y, binsX, binsY)
h = histogram2(ax, X, Y, Name, Value, ...)
histogram2(X, Y)
histogram2(X, Y, bins)
histogram2(ax, X, Y)
histogram2(ax, X, Y, Name, Value, ...)

Inputs

NameTypeRequiredDefaultDescription
XAnyYes—X-axis input samples.
YAnyYes—Y-axis input samples.
binsAnyYes—Scalar/two-element bin count or edge specification.
binsXAnyYes—X-axis bin count scalar or edge vector.
binsYAnyYes—Y-axis bin count scalar or edge vector.
nameValuePairsAnyVariadic—Binning and chart name/value options.
axAxesHandleYes—Target axes handle.

Returns

NameTypeDescription
hNumericScalarHandle to the created histogram2 chart.

Errors

IdentifierWhenMessage
RunMat:histogram2:InvalidArgumentInput arrays, bin controls, or chart options are malformed.histogram2: invalid argument
RunMat:histogram2:InternalRunMat cannot compute bins, register state, or render the chart.histogram2: internal error

How histogram2 works

  • histogram2(X,Y) requires X and Y to contain the same number of elements and ignores pairs containing NaN.
  • Positional bin arguments and name/value bin controls are forwarded through the same implementation as histcounts2, including NumBins, explicit XBinEdges/YBinEdges, BinWidth, BinLimits, BinMethod, axis-specific bin controls, and normalization modes.
  • Returned handles have type histogram2 and expose Values, BinCounts, XBinEdges, YBinEdges, NumBins, Normalization, DisplayStyle, ShowEmptyBins, FaceAlpha, and DisplayName through get.
  • set supports updating Normalization, DisplayStyle, ShowEmptyBins, FaceAlpha, and DisplayName, rebuilding the rendered surface and handle state.
  • Common styling name/value pairs FaceColor, EdgeColor, EdgeAlpha, and LineStyle are accepted for MATLAB script compatibility, but RunMat currently maps the chart through a colormapped surface backend rather than per-bin bar primitives.

Examples

Create a 2-D histogram with two bins per axis

h = histogram2([0; 0.2; 0.8; 1], [0; 0.1; 0.9; 1], [2 2]);
get(h, 'Values')

Expected output:

ans =
     2     0
     0     2

Use probability normalization and tile display

h = histogram2(x, y, 'NumBins', [20 10], 'Normalization', 'probability', 'DisplayStyle', 'tile');
get(h, 'Normalization')

Expected output:

ans =
    'probability'

Inspect and update chart properties

h = histogram2(x, y, 'XBinEdges', 0:0.1:1, 'YBinEdges', -1:0.2:1);
set(h, 'DisplayStyle', 'tile', 'ShowEmptyBins', 'off');
get(h, 'NumBins')

Expected output:

ans = [10 10]

Using histogram2 with coding agents

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

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

FAQ

How is histogram2 related to histcounts2?⌄

histogram2 uses the same binning and normalization logic as histcounts2, then wraps the resulting count matrix in a plotting object.

Which display styles are supported?⌄

'bar3' and 'tile' are supported. bar3 is rendered as a raised colormapped count surface; tile is rendered as a flattened colormapped surface with image-mode camera behavior.

Can histogram2 plot GPU arrays?⌄

Yes, but today it follows the underlying histcounts2 gather-immediate path and renders from the materialized bin grid. Future provider kernels can accelerate the binning stage without changing the plotting API.

Related Plotting functions

2D Charts

area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem

3D & Surface

contour · contour3 · contourf · mesh · meshc · plot3 · quiver · scatter3 · surf · surfc

Images

image · imagesc · imshow

Axes & Layout

axis · box · grid · sgtitle · subplot · title · view · zlabel

Appearance

colorbar · colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

addpoints · ancestor · animatedline · axes · barh · caxis · cla · clf · clim · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · text · textscatter · textscatter3 · triplot · waitbar · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom

Open-source implementation

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

  • View the source for histogram2 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.

Getting started · Benchmarks · Pricing

Download RunMat

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

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How histogram2 works
  • Examples
  • Create a 2-D histogram with two bins per axis
  • Use probability normalization and tile display
  • Inspect and update chart properties
  • Using histogram2 with coding agents
  • FAQ
  • Related Plotting functions
  • 2D Charts
  • 3D & Surface
  • Images
  • Axes & Layout
  • Appearance
  • Handle Access
  • Other
  • Open-source implementation
  • About RunMat