Skip to content

Commit f60b0c6

Browse files
Consistently use construct_color_bar() (#16)
* use construct_color_bar consistently * Add info on ColorBar object * Fix typo * Fix envs * fix env indentation * Update notebooks/05_styling.ipynb --------- Co-authored-by: Ian Thomas <[email protected]>
1 parent 87b8363 commit f60b0c6

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

notebooks/05_styling.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@
673673
"cell_type": "markdown",
674674
"metadata": {},
675675
"source": [
676+
"The ``construct_color_bar()`` method automatically creates a `ColorBar` object. This\n",
677+
"method uses the color mapper of the object you call it on.\n",
678+
"\n",
679+
"You can also create a `ColorBar` object manually.\n",
676680
"See [Color bars](https://docs.bokeh.org/en/latest/docs/user_guide/basic/annotations.html#color-bars)\n",
677681
"in the user guide for more information."
678682
]

notebooks/09_more_plot_types.ipynb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
"* Configuring plot tools\n",
358358
"* Configuring visual elements of the plot\n",
359359
"* Using a ColorMapper to map values to colors from a palette\n",
360-
"* Adding a ColorBar as a visual guide"
360+
"* Adding a color bar as a visual guide"
361361
]
362362
},
363363
{
@@ -369,7 +369,7 @@
369369
"import geopandas as gpd\n",
370370
"\n",
371371
"from bokeh.plotting import figure, show\n",
372-
"from bokeh.models import ColorBar, GeoJSONDataSource, NumeralTickFormatter\n",
372+
"from bokeh.models import GeoJSONDataSource, NumeralTickFormatter\n",
373373
"from bokeh.palettes import Cividis\n",
374374
"from bokeh.transform import linear_cmap\n",
375375
"\n",
@@ -410,7 +410,7 @@
410410
")\n",
411411
"\n",
412412
"# add color bar\n",
413-
"color_bar = ColorBar(color_mapper=us.glyph.fill_color.transform, formatter=NumeralTickFormatter(format=\"0,0\"), orientation=\"horizontal\", height=10)\n",
413+
"color_bar = us.construct_color_bar(formatter=NumeralTickFormatter(format=\"0,0\"), height=10)\n",
414414
"map_plot.add_layout(obj=color_bar, place=\"below\")\n",
415415
"\n",
416416
"show(map_plot)"
@@ -724,11 +724,6 @@
724724
"nbconvert_exporter": "python",
725725
"pygments_lexer": "ipython3",
726726
"version": "3.11.4"
727-
},
728-
"vscode": {
729-
"interpreter": {
730-
"hash": "0494a81e5f69860dcb844ce8e12eb9c88a7e813ddbfb0fbade72137f5ce45437"
731-
}
732727
}
733728
},
734729
"nbformat": 4,

notebooks/12_demo_dashboard.ipynb

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@
12931293
"source": [
12941294
"import geopandas as gpd\n",
12951295
"\n",
1296-
"from bokeh.models import ColorBar, GeoJSONDataSource\n",
1296+
"from bokeh.models import GeoJSONDataSource\n",
12971297
"from bokeh.palettes import Cividis\n",
12981298
"from bokeh.transform import linear_cmap"
12991299
]
@@ -1422,21 +1422,16 @@
14221422
"cell_type": "markdown",
14231423
"metadata": {},
14241424
"source": [
1425-
"- Set up and add the **[ColorBar](05_styling.ipynb#Color-mappers-and-pallets)**.\n",
1426-
" The ColorBar provides a key to which color relates to which\n",
1425+
"- Set up and add the **[color bar](05_styling.ipynb#Color-mappers-and-pallets)**.\n",
1426+
" The color bar provides a key to which color relates to which\n",
14271427
" number of routes. Adding the color bar takes two steps:\n",
1428-
" 1. Defining the color bar as a ``ColorBar`` object. This uses the following\n",
1429-
" parameters:\n",
1430-
" - `color_mapper`: The color mapper to use. In this case, you use the\n",
1431-
" linear color mapper that you defined for the patches renderer in the\n",
1432-
" previous step.\n",
1428+
" 1. Defining the color bar with the ``construct_color_bar()`` method. This uses the\n",
1429+
" following parameters:\n",
14331430
" - `formatter`: How to format the numbers in the color bar. Use a\n",
14341431
" `NumeralTickFormatter` with the format string `0,0`. This means that\n",
14351432
" Bokeh uses a comma as a thousands separator.\n",
1436-
" - `orientation`: The orientation of the color bar. In this case, create a\n",
1437-
" horizontal color bar by setting the value to `\"horizontal\"`.\n",
14381433
" - `height`: The height of the color bar in pixels.\n",
1439-
" 2. Adding the `ColorBar` object to the figure. Use the `add_layout` method to\n",
1434+
" 2. Adding the color bar to the figure. Use the `add_layout` method to\n",
14401435
" add the object and place it below the map plot."
14411436
]
14421437
},
@@ -1447,7 +1442,8 @@
14471442
"outputs": [],
14481443
"source": [
14491444
"# add the color bar\n",
1450-
"color_bar = ColorBar(color_mapper=us.glyph.fill_color.transform, formatter=NumeralTickFormatter(format=\"0,0\"), orientation=\"horizontal\", height=10)\n",
1445+
"color_bar = us.construct_color_bar(formatter=NumeralTickFormatter(format=\"0,0\"), height=10)\n",
1446+
"\n",
14511447
"map_plot.add_layout(obj=color_bar, place=\"below\")"
14521448
]
14531449
},
@@ -1482,7 +1478,7 @@
14821478
"source": [
14831479
"import geopandas as gpd\n",
14841480
"\n",
1485-
"from bokeh.models import ColorBar, GeoJSONDataSource\n",
1481+
"from bokeh.models import GeoJSONDataSource\n",
14861482
"from bokeh.palettes import Cividis\n",
14871483
"from bokeh.transform import linear_cmap\n",
14881484
"\n",
@@ -1523,7 +1519,7 @@
15231519
")\n",
15241520
"\n",
15251521
"# add color bar\n",
1526-
"color_bar = ColorBar(color_mapper=us.glyph.fill_color.transform, formatter=NumeralTickFormatter(format=\"0,0\"), orientation=\"horizontal\", height=10)\n",
1522+
"color_bar = us.construct_color_bar(formatter=NumeralTickFormatter(format=\"0,0\"), height=10)\n",
15271523
"map_plot.add_layout(obj=color_bar, place=\"below\")\n",
15281524
"\n",
15291525
"show(map_plot)"
@@ -1928,11 +1924,6 @@
19281924
"nbconvert_exporter": "python",
19291925
"pygments_lexer": "ipython3",
19301926
"version": "3.11.4"
1931-
},
1932-
"vscode": {
1933-
"interpreter": {
1934-
"hash": "0494a81e5f69860dcb844ce8e12eb9c88a7e813ddbfb0fbade72137f5ce45437"
1935-
}
19361927
}
19371928
},
19381929
"nbformat": 4,

notebooks/tutorial_dashboard.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import geopandas as gpd
55
from bokeh.layouts import column, layout
66
from bokeh.models import (
7-
ColorBar,
87
ColumnDataSource,
98
CustomJS,
109
Div,
@@ -245,7 +244,7 @@ def departures_map():
245244
)
246245

247246
# add color bar
248-
color_bar = ColorBar(color_mapper=us.glyph.fill_color.transform, formatter=NumeralTickFormatter(format="0,0"), orientation="horizontal", height=10)
247+
color_bar = us.construct_color_bar(formatter=NumeralTickFormatter(format="0,0"), height=10)
249248
map_plot.add_layout(obj=color_bar, place="below")
250249

251250
return map_plot

0 commit comments

Comments
 (0)