Plotting

numbl supports a wide range of 2-D and 3-D plot types. In the browser, plots render directly in the IDE. On the command line, use --plot to open a plot server.

Plot Types

Category Functions
Line plot, plot3, line, fplot, fplot3, stairs, errorbar, area
Log axes semilogx, semilogy, loglog
Scatter scatter, scatter3, swarmchart, swarmchart3
Bar bar, barh, bar3, bar3h
Surface surf, surface, mesh, waterfall, pcolor, trimesh, trisurf
Patch patch, fill
Contour contour, contourf
Image imagesc, heatmap
Vector quiver, quiver3, streamline
Volume isosurface
Statistical histogram, histogram2, boxchart, piechart, donutchart

Figure Management

figure, subplot, tiledlayout, nexttile, title, xlabel, ylabel, zlabel, sgtitle, legend, hold, grid, box, axis, xlim, ylim, caxis, clim, view, colormap, colorbar, shading, gca, gcf, set, get, close, clf, cla, drawnow, pause

colormap accepts MATLAB's named colormaps (parula, the default, jet, hsv, hot, cool, spring, summer, autumn, winter, gray, bone, copper, pink), redblue, or an n-by-3 matrix of RGB values in [0, 1]. The functions of the same names return the table: hot(64) is a 64-by-3 matrix, and jet alone has 256 rows. numbl's parula approximates MATLAB's.

For figures that render custom HTML (uihtml), see the repository guide docs/uihtml-figures.md.

Examples

Line Plot

x = linspace(0, 2*pi, 100);
plot(x, sin(x), 'b-', x, cos(x), 'r--');
title('Trig functions');
legend('sin', 'cos');

Surface Plot

[X, Y] = meshgrid(-2:0.1:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X, Y, Z);
colormap('jet');
colorbar;

Subplots

subplot(2, 1, 1);
plot(1:10, rand(1, 10));
title('Random data');

subplot(2, 1, 2);
bar(1:5, randi(10, 1, 5));
title('Bar chart');

3-D Scatter

n = 200;
x = randn(n, 1);
y = randn(n, 1);
z = randn(n, 1);
scatter3(x, y, z, 20, z, 'filled');
colormap('cool');

CLI Usage

To view plots when running from the command line:

numbl run --plot script.m
numbl --plot              # REPL with plot server

The plot server opens a browser window. In the REPL it updates after each command; with numbl run --plot, the figures appear when the script finishes.

In the plot server's window, 2-D plots can be zoomed (scroll), panned (drag) and given new color limits (scroll or drag on the colorbar); double-click resets the view.

Plotting from C and C++

A C or C++ program can send its arrays and MATLAB plot commands to the same viewer while it runs. See Live Plots from C/C++.