|
13 | 13 | - provide a sensible API for adding user interactions (panning, zooming, selection, etc)
|
14 | 14 | - pip installable
|
15 | 15 |
|
16 |
| -Two main APIs are provided |
| 16 | +Two APIs are provided |
17 | 17 |
|
18 | 18 | - Users can build a custom visualization using our object model, that is inspired by
|
19 | 19 | the constructs of the Grammar of Graphics (figure, marks, axes, scales), and enrich their
|
@@ -67,92 +67,62 @@ This package depends on the following packages:
|
67 | 67 |
|
68 | 68 |
|
69 | 69 | ### Loading `bqplot`
|
70 |
| - # In an IPython shell |
71 |
| - $ ipython |
72 |
| - In [1]: import bqplot |
| 70 | +
|
| 71 | +```python |
| 72 | +# In a Jupyter notebook |
| 73 | +import bqplot |
| 74 | +``` |
73 | 75 |
|
74 | 76 | That's it! You're ready to go!
|
75 | 77 |
|
76 | 78 | Examples
|
77 | 79 | --------
|
78 | 80 |
|
79 |
| -1. Using the `bqplot` internal object model |
80 |
| -
|
81 |
| -
|
82 |
| - ```python |
83 |
| - import numpy as np |
84 |
| - from IPython.display import display |
85 |
| - from bqplot import * |
86 |
| -
|
87 |
| - n = 10 |
88 |
| - x_data = np.arange(n) |
89 |
| - y_data = np.cumsum(np.random.randn(n)) * 100.0 |
90 |
| - y_data_2 = np.cumsum(np.random.randn(n)) * 100.0 |
91 |
| - y_data_3 = np.cumsum(np.random.randn(n)) * 100.0 |
92 |
| -
|
93 |
| - sc_ord = OrdinalScale() |
94 |
| - sc_y = LinearScale() |
95 |
| - sc_y_2 = LinearScale() |
96 |
| -
|
97 |
| - ord_ax = Axis(scale=sc_ord, |
98 |
| - label='Test X', |
99 |
| - tick_format='0.0f', |
100 |
| - grid_lines='none') |
101 |
| -
|
102 |
| - y_ax = Axis(scale=sc_y, |
103 |
| - label='Test Y', |
104 |
| - tick_format='0.2f', |
105 |
| - grid_lines='solid', |
106 |
| - orientation='vertical') |
107 |
| -
|
108 |
| - y_ax_2 = Axis(label='Test Y 2', |
109 |
| - scale=sc_y_2, |
110 |
| - orientation='vertical', |
111 |
| - side='right', |
112 |
| - tick_format='0.0f', |
113 |
| - grid_lines='dashed') |
114 |
| -
|
115 |
| - line_chart = Lines(x=x_data, |
116 |
| - y=[y_data, y_data_2, y_data_3], |
117 |
| - scales={ |
118 |
| - 'x': sc_ord, |
119 |
| - 'y': sc_y, |
120 |
| - }, |
121 |
| - stroke_width=3, |
122 |
| - labels=['Line1', 'Line2', 'Line3'], |
123 |
| - display_legend=True) |
124 |
| -
|
125 |
| - bar_chart = Bars(x=x_data, |
126 |
| - y=[y_data, y_data_2, y_data_3], |
127 |
| - scales={ |
128 |
| - 'x': sc_ord, |
129 |
| - 'y': sc_y_2, |
130 |
| - }, |
131 |
| - opacity=0.5, |
132 |
| - labels=['Bar1', 'Bar2', 'Bar3'], |
133 |
| - display_legend=True) |
134 |
| -
|
135 |
| - fig = Figure(axes=[ord_ax, y_ax, y_ax_2], |
136 |
| - marks=[bar_chart, line_chart], |
137 |
| - legend_location='top-left') |
138 |
| -
|
139 |
| - display(fig) |
140 |
| - ``` |
| 81 | +### Using the `pyplot` API |
141 | 82 |
|
142 |
| -2. Using the `pyplot` API |
| 83 | +```python |
| 84 | +from bqplot import pyplot as plt |
| 85 | +import numpy as np |
143 | 86 |
|
144 |
| - ```python |
145 |
| - from bqplot import pyplot as plt |
146 |
| - import numpy as np |
| 87 | +plt.figure(1) |
| 88 | +np.random.seed(0) |
| 89 | +n = 200 |
| 90 | +x = np.linspace(0.0, 10.0, n) |
| 91 | +y = np.cumsum(np.random.randn(n)) |
| 92 | +plt.plot(x,y, axes_options={'y': {'grid_lines': 'dashed'}}) |
| 93 | +plt.show() |
| 94 | +``` |
147 | 95 |
|
148 |
| - plt.figure(1) |
149 |
| - np.random.seed(0) |
150 |
| - n = 200 |
151 |
| - x = np.linspace(0.0, 10.0, n) |
152 |
| - y = np.cumsum(np.random.randn(n)) |
153 |
| - plt.plot(x,y, axes_options={'y': {'grid_lines': 'dashed'}}) |
154 |
| - plt.show() |
155 |
| - ``` |
| 96 | + |
| 97 | + |
| 98 | +### Using the `bqplot` internal object model |
| 99 | + |
| 100 | + |
| 101 | +```python |
| 102 | +import numpy as np |
| 103 | +from IPython.display import display |
| 104 | +from bqplot import * |
| 105 | + |
| 106 | +size = 20 |
| 107 | +np.random.seed(0) |
| 108 | + |
| 109 | +x_data = np.arange(size) |
| 110 | + |
| 111 | +x_ord = OrdinalScale() |
| 112 | +y_sc = LinearScale() |
| 113 | + |
| 114 | +bar = Bars(x=x_data, y=np.random.randn(2, size), scales={'x': x_ord, 'y': y_sc}, type='stacked') |
| 115 | +line = Lines(x=x_data, y=np.random.randn(size), scales={'x': x_ord, 'y': y_sc}, |
| 116 | + stroke_width=3, colors=['red'], display_legend=True, labels=['Line chart']) |
| 117 | + |
| 118 | +ax_x = Axis(scale=x_ord) |
| 119 | +ax_y = Axis(scale=y_sc, orientation='vertical', tick_format='0.2f', grid_lines='solid') |
| 120 | + |
| 121 | +fig = Figure(marks=[bar, line], axes=[ax_x, ax_y]) |
| 122 | +display(fig) |
| 123 | +``` |
| 124 | + |
| 125 | + |
156 | 126 |
|
157 | 127 | License
|
158 | 128 | -------
|
|
0 commit comments