| 1 |
Usage |
| 2 |
===== |
| 3 |
|
| 4 |
The following code examples are static, but you can make them executable and test bqplot |
| 5 |
by clicking the following button: |
| 6 |
|
| 7 |
.. thebe-button:: Click me! |
| 8 |
|
| 9 |
Examples |
| 10 |
-------- |
| 11 |
|
| 12 |
Using the pyplot API: |
| 13 |
|
| 14 |
.. jupyter-execute:: |
| 15 |
|
| 16 |
import numpy as np |
| 17 |
from bqplot import pyplot as plt |
| 18 |
|
| 19 |
plt.figure(1, title="Line Chart") |
| 20 |
np.random.seed(0) |
| 21 |
n = 200 |
| 22 |
x = np.linspace(0.0, 10.0, n) |
| 23 |
y = np.cumsum(np.random.randn(n)) |
| 24 |
plt.plot(x, y) |
| 25 |
plt.show() |
| 26 |
|
| 27 |
Using the bqplot internal object model: |
| 28 |
|
| 29 |
.. jupyter-execute:: |
| 30 |
|
| 31 |
import numpy as np |
| 32 |
from IPython.display import display |
| 33 |
from bqplot import OrdinalScale, LinearScale, Bars, Lines, Axis, Figure |
| 34 |
|
| 35 |
size = 20 |
| 36 |
np.random.seed(0) |
| 37 |
|
| 38 |
x_data = np.arange(size) |
| 39 |
|
| 40 |
x_ord = OrdinalScale() |
| 41 |
y_sc = LinearScale() |
| 42 |
|
| 43 |
bar = Bars( |
| 44 |
x=x_data, y=np.random.randn(2, size), scales={"x": x_ord, "y": y_sc}, type="stacked" |
| 45 |
) |
| 46 |
line = Lines( |
| 47 |
x=x_data, |
| 48 |
y=np.random.randn(size), |
| 49 |
scales={"x": x_ord, "y": y_sc}, |
| 50 |
stroke_width=3, |
| 51 |
colors=["red"], |
| 52 |
display_legend=True, |
| 53 |
labels=["Line chart"], |
| 54 |
) |
| 55 |
|
| 56 |
ax_x = Axis(scale=x_ord, grid_lines="solid", label="X") |
| 57 |
ax_y = Axis( |
| 58 |
scale=y_sc, |
| 59 |
orientation="vertical", |
| 60 |
tick_format="0.2f", |
| 61 |
grid_lines="solid", |
| 62 |
label="Y", |
| 63 |
) |
| 64 |
|
| 65 |
Figure( |
| 66 |
marks=[bar, line], |
| 67 |
axes=[ax_x, ax_y], |
| 68 |
title="API Example", |
| 69 |
legend_location="bottom-right", |
| 70 |
) |