File: usage.rst

package info (click to toggle)
bqplot 0.12.32-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 18,072 kB
  • sloc: python: 2,573; makefile: 162; javascript: 150
file content (70 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Usage
=====

The following code examples are static, but you can make them executable and test bqplot
by clicking the following button:

.. thebe-button:: Click me!

Examples
--------

Using the pyplot API:

.. jupyter-execute::

    import numpy as np
    from bqplot import pyplot as plt

    plt.figure(1, title="Line Chart")
    np.random.seed(0)
    n = 200
    x = np.linspace(0.0, 10.0, n)
    y = np.cumsum(np.random.randn(n))
    plt.plot(x, y)
    plt.show()

Using the bqplot internal object model:

.. jupyter-execute::

    import numpy as np
    from IPython.display import display
    from bqplot import OrdinalScale, LinearScale, Bars, Lines, Axis, Figure

    size = 20
    np.random.seed(0)

    x_data = np.arange(size)

    x_ord = OrdinalScale()
    y_sc = LinearScale()

    bar = Bars(
        x=x_data, y=np.random.randn(2, size), scales={"x": x_ord, "y": y_sc}, type="stacked"
    )
    line = Lines(
        x=x_data,
        y=np.random.randn(size),
        scales={"x": x_ord, "y": y_sc},
        stroke_width=3,
        colors=["red"],
        display_legend=True,
        labels=["Line chart"],
    )

    ax_x = Axis(scale=x_ord, grid_lines="solid", label="X")
    ax_y = Axis(
        scale=y_sc,
        orientation="vertical",
        tick_format="0.2f",
        grid_lines="solid",
        label="Y",
    )

    Figure(
        marks=[bar, line],
        axes=[ax_x, ax_y],
        title="API Example",
        legend_location="bottom-right",
    )