colorbar — Show or hide colorbars for images, surfaces, contours, and MATLAB colorbar workflows.
colorbar toggles the visibility of the color scale associated with the current axes. In RunMat it is subplot-local and is most often used with imagesc, image, surf, contourf, and related colormap-driven visualizations.
How colorbar works in RunMat
colorbar onenables the colorbar for the current axes.colorbar offdisables the colorbar for the current axes.- Calling
colorbarwith 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;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.
Related functions to explore
These functions work well alongside colorbar. Each page has runnable examples you can try in the browser.
colormap, imagesc, surf, contourf
More plotting resources
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how colorbar works, line by line, in Rust.
- View colorbar.rs on GitHub
- Learn how the 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 — faster, on any GPU, with no license required.
- Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
- Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
- A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.