/ concept-collection / jupyterlite-numbl-kernel
Sign in
concept-collection / jupyterlite-numbl-kernel
jupyterlite-numbl-kernel / demo / content / advanced / 07-plotting-gallery.ipynb
127 lines · 3.1 KBBlameHistoryRaw
1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "pl-0",
6 "metadata": {},
7 "source": "# Plotting gallery\n\nEach cell renders its figures into the cell output. 3-D figures are\ninteractive (drag to rotate)."
8 },
9 {
10 "cell_type": "markdown",
11 "id": "pl-1",
12 "metadata": {},
13 "source": "## Line plots with styles and a legend"
14 },
15 {
16 "cell_type": "code",
17 "id": "pl-2",
18 "metadata": {},
19 "execution_count": null,
20 "outputs": [],
21 "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');"
22 },
23 {
24 "cell_type": "markdown",
25 "id": "pl-3",
26 "metadata": {},
27 "source": "## Scatter plots"
28 },
29 {
30 "cell_type": "code",
31 "id": "pl-4",
32 "metadata": {},
33 "execution_count": null,
34 "outputs": [],
35 "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');"
36 },
37 {
38 "cell_type": "markdown",
39 "id": "pl-5",
40 "metadata": {},
41 "source": "## Bar charts and histograms"
42 },
43 {
44 "cell_type": "code",
45 "id": "pl-6",
46 "metadata": {},
47 "execution_count": null,
48 "outputs": [],
49 "source": "bar([5 3 8 2 7]);\ntitle('bar chart');"
50 },
51 {
52 "cell_type": "code",
53 "id": "pl-7",
54 "metadata": {},
55 "execution_count": null,
56 "outputs": [],
57 "source": "rng(0);\nhistogram(randn(1, 1000));\ntitle('1000 normal samples');"
58 },
59 {
60 "cell_type": "markdown",
61 "id": "pl-8",
62 "metadata": {},
63 "source": "## Surfaces and contours"
64 },
65 {
66 "cell_type": "code",
67 "id": "pl-9",
68 "metadata": {},
69 "execution_count": null,
70 "outputs": [],
71 "source": "[X, Y] = meshgrid(linspace(-3, 3, 40));\nZ = X .* exp(-X.^2 - Y.^2);\nsurf(Z);\ntitle('a surface (drag to rotate)');"
72 },
73 {
74 "cell_type": "code",
75 "id": "pl-10",
76 "metadata": {},
77 "execution_count": null,
78 "outputs": [],
79 "source": "contour(peaks(60));\ntitle('contours of peaks');"
80 },
81 {
82 "cell_type": "markdown",
83 "id": "pl-11",
84 "metadata": {},
85 "source": "## Images and colorbars"
86 },
87 {
88 "cell_type": "code",
89 "id": "pl-12",
90 "metadata": {},
91 "execution_count": null,
92 "outputs": [],
93 "source": "imagesc(magic(8));\ncolorbar;\ntitle('magic(8)');"
94 },
95 {
96 "cell_type": "markdown",
97 "id": "pl-13",
98 "metadata": {},
99 "source": "## Subplots"
100 },
101 {
102 "cell_type": "code",
103 "id": "pl-14",
104 "metadata": {},
105 "execution_count": null,
106 "outputs": [],
107 "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');"
108 }
109 ],
110 "metadata": {
111 "kernelspec": {
112 "display_name": "numbl (MATLAB syntax)",
113 "language": "numbl",
114 "name": "numbl"
115 },
116 "language_info": {
117 "codemirror_mode": "octave",
118 "file_extension": ".m",
119 "mimetype": "text/x-octave",
120 "name": "numbl",
121 "nbconvert_exporter": "script",
122 "pygments_lexer": "matlab"
123 }
124 },
125 "nbformat": 4,
126 "nbformat_minor": 5
moveopenescclose