|
53 | 53 | "source": [
|
54 | 54 | "This chapter provides an overview of the tools that are available in the Bokeh toolbar.\n",
|
55 | 55 | "\n",
|
| 56 | + "\n", |
| 57 | + "\n", |
56 | 58 | "The Bokeh toolbar is a collection of tools that are displayed together with a plot.\n",
|
57 | 59 | "You have seen the toolbar in all previous examples. This chapter is about configuring\n",
|
58 | 60 | "the toolbar and its tools."
|
|
112 | 114 | "When you configure the toolbar with the ``figure()`` method, you can specify **which\n",
|
113 | 115 | "tools to include**.\n",
|
114 | 116 | "\n",
|
115 |
| - "You can pass a list of tool names to the `tools` argument. The following list contains\n", |
| 117 | + "You can pass a sequence of tool names to the `tools` argument. The following list contains\n", |
116 | 118 | "some of the most commonly used tools for viewing data:\n",
|
117 | 119 | "\n",
|
118 | 120 | "* `pan` - pan the plot\n",
|
|
139 | 141 | "# set up a figure with a toolbar\n",
|
140 | 142 | "p = figure(\n",
|
141 | 143 | " height=300,\n",
|
142 |
| - " tools=[\"box_zoom\", \"wheel_zoom\", \"save\"], # 🔁 swap out tools from the list above\n", |
| 144 | + " tools=(\"box_zoom\", \"wheel_zoom\", \"save\"), # 🔁 swap out tools from the list above\n", |
143 | 145 | ")\n",
|
144 | 146 | "\n",
|
145 | 147 | "p.line(x=list(range(10)), y=list(range(10)))\n",
|
|
167 | 169 | "source": [
|
168 | 170 | "### Defining active tools\n",
|
169 | 171 | "\n",
|
170 |
| - "By default, Bokeh will activate the first tool in the list of tools. You can **change\n", |
171 |
| - "which tools are active** by setting the ``active_drag``, ``active_inspect``,`\n", |
| 172 | + "You can **change which tools are active** by setting the ``active_drag``, ``active_inspect``,\n", |
172 | 173 | "``active_scroll``, and ``active_tap`` properties of a toolbar.\n",
|
173 | 174 | "\n",
|
174 | 175 | "The reason why Bokeh has separate properties for different types of tools is that\n",
|
175 | 176 | "you can have several tools of different types active at the same time. For example,\n",
|
176 | 177 | "you can have an active scroll tool and an active inspect tool at the same time.\n",
|
177 | 178 | "\n",
|
178 |
| - "The following code cell uses the ``xwenel_zoom`` tool as its active scroll tool.\n", |
179 |
| - "Update the code in line 7 to make the ``ywheel_zoom`` tool active by default instead:" |
| 179 | + "The following code cell uses the ``xpan`` tool as its active drag tool.\n", |
| 180 | + "Update the code in line 7 to make the ``ypan`` tool active by default instead:" |
180 | 181 | ]
|
181 | 182 | },
|
182 | 183 | {
|
|
190 | 191 | "# set up a figure with a toolbar\n",
|
191 | 192 | "p = figure(\n",
|
192 | 193 | " height=300,\n",
|
193 |
| - " tools=[\"reset\", \"wheel_zoom\", \"xwheel_zoom\", \"save\"],\n", |
194 |
| - " active_scroll=\"xwheel_zoom\", # 🔁 update this line to make \"xwheel_zoom\" the active scroll tool\n", |
| 194 | + " tools=(\"reset\", \"pan\", \"ypan\", \"xpan\", \"save\"),\n", |
| 195 | + " active_drag=\"xpan\", # 🔁 update this line to make \"ypan\" the active drag tool\n", |
195 | 196 | ")\n",
|
196 | 197 | "\n",
|
197 | 198 | "p.line(x=list(range(10)), y=list(range(10)))\n",
|
|
208 | 209 | "The `HoverTool` is a special tool that **displays a tooltip when the user hovers the\n",
|
209 | 210 | "mouse over a data point or taps on a data point**.\n",
|
210 | 211 | "\n",
|
211 |
| - "To enable tooltips, you need to add a `HoverTool` to the list of tools. You can then\n", |
| 212 | + "To enable tooltips, you need to add a `hover` tool to the list of tools. You can then\n", |
212 | 213 | "use the `tooltips` argument to specify which data fields to display in the tooltip.\n",
|
213 | 214 | "\n",
|
214 | 215 | "Run the cell below and hover over the data points:"
|
|
225 | 226 | "\n",
|
226 | 227 | "source = ColumnDataSource(\n",
|
227 | 228 | " data={\n",
|
228 |
| - " \"x\": [1, 2, 3, 4, 5],\n", |
229 |
| - " \"y\": [3, 7, 8, 5, 1],\n", |
| 229 | + " \"x\": [1, 2, 3, 6, 9],\n", |
| 230 | + " \"y\": [3, 7, 8, 2, 1],\n", |
230 | 231 | " }\n",
|
231 | 232 | ")\n",
|
232 | 233 | "\n",
|
233 | 234 | "p = figure(\n",
|
234 | 235 | " toolbar_location=None,\n",
|
235 |
| - " tools=[HoverTool()], # add the HoverTool to the figure\n", |
236 |
| - " tooltips=\"Data point @x has the value @y\", # define a tooltip using data from the x and y columns\n", |
| 236 | + " tools=\"hover\", # add the hover tool to the figure (the hover tool will work even if the toolbar is hidden)\n", |
| 237 | + " tooltips=\"Data point is at @x, @y\", # define a tooltip using data from the x and y columns\n", |
237 | 238 | " height=300,\n",
|
238 | 239 | ")\n",
|
239 | 240 | "\n",
|
240 | 241 | "# add renderers\n",
|
241 |
| - "p.circle(\"x\", \"y\", size=10, source=source)\n", |
| 242 | + "p.circle(\"x\", \"y\", size=25, source=source)\n", |
242 | 243 | "p.line(\"x\", \"y\", line_width=2, source=source)\n",
|
243 | 244 | "\n",
|
244 | 245 | "# show the results\n",
|
|
253 | 254 | "The text that is displayed in the tooltip uses **special syntax to refer to data from\n",
|
254 | 255 | "the ColumnDataSource**.\n",
|
255 | 256 | "\n",
|
256 |
| - "In the example above, the tooltip text is `\"Data point @x has the value @y\"`. The `@x`\n", |
| 257 | + "In the example above, the tooltip text is `\"Data point is at @x, @y`. The `@x`\n", |
257 | 258 | "and `@y` are replaced with the actual value of the `x` and `y` columns in the\n",
|
258 | 259 | "ColumnDataSource at that point.\n",
|
259 | 260 | "\n",
|
|
0 commit comments