{ "cells": [ { "cell_type": "markdown", "id": "pl-0", "metadata": {}, "source": "# Plotting gallery\n\nEach cell renders its figures into the cell output. 3-D figures are\ninteractive (drag to rotate)." }, { "cell_type": "markdown", "id": "pl-1", "metadata": {}, "source": "## Line plots with styles and a legend" }, { "cell_type": "code", "id": "pl-2", "metadata": {}, "execution_count": null, "outputs": [], "source": "x = linspace(0, 2 * pi, 200);\nplot(x, sin(x), 'b-');\nhold on;\nplot(x, cos(x), 'r--');\nhold off;\nlegend('sin', 'cos');\nxlabel('x'); ylabel('y'); title('sine and cosine');" }, { "cell_type": "markdown", "id": "pl-3", "metadata": {}, "source": "## Scatter plots" }, { "cell_type": "code", "id": "pl-4", "metadata": {}, "execution_count": null, "outputs": [], "source": "rng(0);\nn = 80;\nxs = randn(1, n);\nys = xs + 0.4 * randn(1, n);\nscatter(xs, ys);\nxlabel('x'); ylabel('y'); title('correlated samples');" }, { "cell_type": "markdown", "id": "pl-5", "metadata": {}, "source": "## Bar charts and histograms" }, { "cell_type": "code", "id": "pl-6", "metadata": {}, "execution_count": null, "outputs": [], "source": "bar([5 3 8 2 7]);\ntitle('bar chart');" }, { "cell_type": "code", "id": "pl-7", "metadata": {}, "execution_count": null, "outputs": [], "source": "rng(0);\nhistogram(randn(1, 1000));\ntitle('1000 normal samples');" }, { "cell_type": "markdown", "id": "pl-8", "metadata": {}, "source": "## Surfaces and contours" }, { "cell_type": "code", "id": "pl-9", "metadata": {}, "execution_count": null, "outputs": [], "source": "[X, Y] = meshgrid(linspace(-3, 3, 40));\nZ = X .* exp(-X.^2 - Y.^2);\nsurf(Z);\ntitle('a surface (drag to rotate)');" }, { "cell_type": "code", "id": "pl-10", "metadata": {}, "execution_count": null, "outputs": [], "source": "contour(peaks(60));\ntitle('contours of peaks');" }, { "cell_type": "markdown", "id": "pl-11", "metadata": {}, "source": "## Images and colorbars" }, { "cell_type": "code", "id": "pl-12", "metadata": {}, "execution_count": null, "outputs": [], "source": "imagesc(magic(8));\ncolorbar;\ntitle('magic(8)');" }, { "cell_type": "markdown", "id": "pl-13", "metadata": {}, "source": "## Subplots" }, { "cell_type": "code", "id": "pl-14", "metadata": {}, "execution_count": null, "outputs": [], "source": "x = linspace(0, 2 * pi, 100);\nsubplot(2, 2, 1); plot(x, sin(x)); title('sin');\nsubplot(2, 2, 2); plot(x, cos(x)); title('cos');\nsubplot(2, 2, 3); plot(x, sin(2 * x)); title('sin(2x)');\nsubplot(2, 2, 4); plot(x, sin(x) .* cos(x)); title('sin*cos');" } ], "metadata": { "kernelspec": { "display_name": "numbl (MATLAB syntax)", "language": "numbl", "name": "numbl" }, "language_info": { "codemirror_mode": "octave", "file_extension": ".m", "mimetype": "text/x-octave", "name": "numbl", "nbconvert_exporter": "script", "pygments_lexer": "matlab" } }, "nbformat": 4, "nbformat_minor": 5 }