RunMat
GitHub

colorbar — Show, hide, or toggle colorbars in MATLAB and RunMat plotting.

colorbar controls visibility of the color scale associated with the current axes. It is axes-local and commonly used with colormap-driven plots such as imagesc, surf, and contourf, matching MATLAB behavior.

Syntax

enabled = colorbar()
enabled = colorbar(mode)

Inputs

NameTypeRequiredDefaultDescription
modeStringScalarNo"toggle"Colorbar mode token ('on'|'off').

Returns

NameTypeDescription
enabledLogicalArrayColorbar enabled state after command execution.

Errors

IdentifierWhenMessage
RunMat:colorbar:InvalidArgumentColorbar mode argument is unsupported.colorbar: invalid argument

How colorbar works

  • colorbar on enables the colorbar for the current axes.
  • colorbar off disables the colorbar for the current axes.
  • Calling colorbar with no argument toggles the current colorbar state.
  • Colorbar visibility is subplot-local and does not automatically affect other axes.

Examples

Show a colorbar for a scaled image

[X, Y] = meshgrid(linspace(-3, 3, 60), linspace(-3, 3, 60));
A = sin(X) .* cos(Y);
imagesc(A);
colorbar on;

Use colorbars independently across subplots

[X, Y] = meshgrid(linspace(-3, 3, 40), linspace(-3, 3, 40));
Z = sin(X) .* cos(Y);
subplot(1, 2, 1);
contourf(X, Y, Z);
colorbar on;
subplot(1, 2, 2);
surf(X, Y, Z);
colorbar off;

Using colorbar with coding agents

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

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

FAQ

How do I add a label to the colorbar?

Use ylabel on the colorbar handle, or label the axes directly. In practice, the colorbar inherits its scale from the data range of the parent plot, and you annotate it through standard label commands on the axes.

imagesc(peaks(50));
colorbar on;
ylabel('Intensity');
Can I limit the colorbar range without clipping the data?

Set caxis([cmin cmax]) (or clim([cmin cmax])) on the axes to control the color mapping range. Values outside that range get clamped to the endpoint colors, but the underlying data stays intact.

Does the colorbar track across subplots automatically?

No. Colorbar state is subplot-local, so each axes manages its own colorbar independently. You need to call colorbar on in each subplot where you want one visible.

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

colormap · legend · shading

Handle Access

gca · gcf · get · set

Other

cla · clf · figure · fill3 · hold · patch · polarplot · print · suptitle · xline · yline

More plotting resources

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how colorbar 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.