Debian Codegraph @

bqplot/examples/Basic Plotting/Basic Plotting.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import numpy as np\n",
10 "import bqplot.pyplot as plt"
11 ]
12 },
13 {
14 "cell_type": "code",
15 "execution_count": null,
16 "metadata": {},
17 "outputs": [],
18 "source": [
19 "size = 100\n",
20 "scale = 100.\n",
21 "np.random.seed(0)\n",
22 "x_data = np.arange(size)\n",
23 "y_data = np.cumsum(np.random.randn(size) * scale)"
24 ]
25 },
26 {
27 "cell_type": "markdown",
28 "metadata": {},
29 "source": [
30 "## Line Chart"
31 ]
32 },
33 {
34 "cell_type": "code",
35 "execution_count": null,
36 "metadata": {},
37 "outputs": [],
38 "source": [
39 "fig = plt.figure(title='First Example')\n",
40 "plt.plot(y_data)\n",
41 "fig"
42 ]
43 },
44 {
45 "cell_type": "markdown",
46 "metadata": {},
47 "source": [
48 "This image can be saved by calling the `save_png` function of the `Figure` object:"
49 ]
50 },
51 {
52 "cell_type": "code",
53 "execution_count": null,
54 "metadata": {},
55 "outputs": [],
56 "source": [
57 "fig.save_png()"
58 ]
59 },
60 {
61 "cell_type": "markdown",
62 "metadata": {},
63 "source": [
64 "## Line Chart with dates as x data"
65 ]
66 },
67 {
68 "cell_type": "code",
69 "execution_count": null,
70 "metadata": {},
71 "outputs": [],
72 "source": [
73 "dates = np.arange('2005-02', '2005-03', dtype='datetime64[D]')\n",
74 "size = len(dates)\n",
75 "prices = scale + 5 * np.cumsum(np.random.randn(size))"
76 ]
77 },
78 {
79 "cell_type": "code",
80 "execution_count": null,
81 "metadata": {},
82 "outputs": [],
83 "source": [
84 "fig = plt.figure(title='Changing Styles', background_style={'fill': 'lightgreen'},\n",
85 " title_style={'font-size': '20px','fill': 'DarkOrange'})\n",
86 "axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},\n",
87 " 'y': {'label': 'Price', 'tick_format': '0.0f'}}\n",
88 "plt.plot(dates, prices, 'b', axes_options=axes_options) # third argument is the marker string\n",
89 "fig"
90 ]
91 },
92 {
93 "cell_type": "markdown",
94 "metadata": {},
95 "source": [
96 "## Scatter Chart"
97 ]
98 },
99 {
100 "cell_type": "code",
101 "execution_count": null,
102 "metadata": {},
103 "outputs": [],
104 "source": [
105 "fig = plt.figure()\n",
106 "axes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},\n",
107 " 'y': {'label': 'Price', 'tick_format': '0.0f'}}\n",
108 "\n",
109 "plt.scatter(x_data, y_data, colors=['red'], stroke='black')\n",
110 "fig"
111 ]
112 },
113 {
114 "cell_type": "markdown",
115 "metadata": {},
116 "source": [
117 "## Histogram"
118 ]
119 },
120 {
121 "cell_type": "code",
122 "execution_count": null,
123 "metadata": {},
124 "outputs": [],
125 "source": [
126 "fig = plt.figure()\n",
127 "plt.hist(y_data)\n",
128 "fig"
129 ]
130 },
131 {
132 "cell_type": "markdown",
133 "metadata": {},
134 "source": [
135 "## Bar Chart"
136 ]
137 },
138 {
139 "cell_type": "code",
140 "execution_count": null,
141 "metadata": {},
142 "outputs": [],
143 "source": [
144 "import string\n",
145 "\n",
146 "fig = plt.figure(padding_x=0)\n",
147 "axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y'}}\n",
148 "plt.bar(x=list(string.ascii_uppercase), y=np.abs(y_data[:20]), axes_options=axes_options)\n",
149 "fig"
150 ]
151 }
152 ],
153 "metadata": {
154 "anaconda-cloud": {},
155 "kernelspec": {
156 "display_name": "Python 3",
157 "language": "python",
158 "name": "python3"
159 },
160 "language_info": {
161 "codemirror_mode": {
162 "name": "ipython",
163 "version": 3
164 },
165 "file_extension": ".py",
166 "mimetype": "text/x-python",
167 "name": "python",
168 "nbconvert_exporter": "python",
169 "pygments_lexer": "ipython3",
170 "version": "3.7.6"
171 }
172 },
173 "nbformat": 4,
174 "nbformat_minor": 2
175 }